mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Fixed minor code nits
- made fixes for the following: - jsdoc definitions - typos - extra parameter to function - missing `utf-8` to fs file read
This commit is contained in:
parent
6719bcf46e
commit
6db20fc14b
2 changed files with 11 additions and 9 deletions
|
@ -14,9 +14,9 @@ const get = require('lodash/get');
|
||||||
class I18n {
|
class I18n {
|
||||||
/**
|
/**
|
||||||
* @param {object} [options]
|
* @param {object} [options]
|
||||||
* @param {string} basePath - the base path to the translations directory
|
* @param {string} options.basePath - the base path to the translations directory
|
||||||
* @param {string} [locale] - a locale string
|
* @param {string} [options.locale] - a locale string
|
||||||
* @param {{dot|fulltext}} [stringMode] - which mode our translation keys use
|
* @param {string} [options.stringMode] - which mode our translation keys use
|
||||||
*/
|
*/
|
||||||
constructor(options = {}) {
|
constructor(options = {}) {
|
||||||
this._basePath = options.basePath || __dirname;
|
this._basePath = options.basePath || __dirname;
|
||||||
|
@ -100,7 +100,7 @@ class I18n {
|
||||||
/**
|
/**
|
||||||
* Attempt to load strings from a file
|
* Attempt to load strings from a file
|
||||||
*
|
*
|
||||||
* @param {sting} [locale]
|
* @param {string} [locale]
|
||||||
* @returns {object} strings
|
* @returns {object} strings
|
||||||
*/
|
*/
|
||||||
_loadStrings(locale) {
|
_loadStrings(locale) {
|
||||||
|
@ -110,7 +110,7 @@ class I18n {
|
||||||
return this._readTranslationsFile(locale);
|
return this._readTranslationsFile(locale);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err.code === 'ENOENT') {
|
if (err.code === 'ENOENT') {
|
||||||
this._handleMissingFileError(locale, err);
|
this._handleMissingFileError(locale);
|
||||||
|
|
||||||
if (locale !== this.defaultLocale()) {
|
if (locale !== this.defaultLocale()) {
|
||||||
this._handleFallbackToDefault();
|
this._handleFallbackToDefault();
|
||||||
|
@ -207,7 +207,7 @@ class I18n {
|
||||||
*/
|
*/
|
||||||
_readTranslationsFile(locale) {
|
_readTranslationsFile(locale) {
|
||||||
const filePath = path.join(...this._translationFileDirs(), this._translationFileName(locale));
|
const filePath = path.join(...this._translationFileDirs(), this._translationFileName(locale));
|
||||||
const content = fs.readFileSync(filePath);
|
const content = fs.readFileSync(filePath, 'utf8');
|
||||||
return JSON.parse(content);
|
return JSON.parse(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,6 +276,7 @@ class I18n {
|
||||||
_handleMissingFileError(locale) {
|
_handleMissingFileError(locale) {
|
||||||
logging.warn(`i18n was unable to find ${locale}.json.`);
|
logging.warn(`i18n was unable to find ${locale}.json.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
_handleInvalidFileError(locale, err) {
|
_handleInvalidFileError(locale, err) {
|
||||||
logging.error(new errors.IncorrectUsageError({
|
logging.error(new errors.IncorrectUsageError({
|
||||||
err,
|
err,
|
||||||
|
|
|
@ -4,9 +4,9 @@ const I18n = require('./I18n');
|
||||||
|
|
||||||
class ThemeI18n extends I18n {
|
class ThemeI18n extends I18n {
|
||||||
/**
|
/**
|
||||||
* @param {objec} [options]
|
* @param {object} [options]
|
||||||
* @param {string} basePath - the base path for the translation directory (e.g. where themes live)
|
* @param {string} options.basePath - the base path for the translation directory (e.g. where themes live)
|
||||||
* @param {string} [locale] - a locale string
|
* @param {string} [options.locale] - a locale string
|
||||||
*/
|
*/
|
||||||
constructor(options = {}) {
|
constructor(options = {}) {
|
||||||
super(options);
|
super(options);
|
||||||
|
@ -48,6 +48,7 @@ class ThemeI18n extends I18n {
|
||||||
logging.warn(`Theme translations file locales/${locale}.json not found.`);
|
logging.warn(`Theme translations file locales/${locale}.json not found.`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_handleInvalidFileError(locale, err) {
|
_handleInvalidFileError(locale, err) {
|
||||||
logging.error(new errors.IncorrectUsageError({
|
logging.error(new errors.IncorrectUsageError({
|
||||||
err,
|
err,
|
||||||
|
|
Loading…
Add table
Reference in a new issue