0
Fork 0
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:
Daniel Lockyer 2024-03-11 21:12:52 +01:00 committed by Daniel Lockyer
parent 6719bcf46e
commit 6db20fc14b
2 changed files with 11 additions and 9 deletions

View file

@ -14,9 +14,9 @@ const get = require('lodash/get');
class I18n {
/**
* @param {object} [options]
* @param {string} basePath - the base path to the translations directory
* @param {string} [locale] - a locale string
* @param {{dot|fulltext}} [stringMode] - which mode our translation keys use
* @param {string} options.basePath - the base path to the translations directory
* @param {string} [options.locale] - a locale string
* @param {string} [options.stringMode] - which mode our translation keys use
*/
constructor(options = {}) {
this._basePath = options.basePath || __dirname;
@ -100,7 +100,7 @@ class I18n {
/**
* Attempt to load strings from a file
*
* @param {sting} [locale]
* @param {string} [locale]
* @returns {object} strings
*/
_loadStrings(locale) {
@ -110,7 +110,7 @@ class I18n {
return this._readTranslationsFile(locale);
} catch (err) {
if (err.code === 'ENOENT') {
this._handleMissingFileError(locale, err);
this._handleMissingFileError(locale);
if (locale !== this.defaultLocale()) {
this._handleFallbackToDefault();
@ -207,7 +207,7 @@ class I18n {
*/
_readTranslationsFile(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);
}
@ -276,6 +276,7 @@ class I18n {
_handleMissingFileError(locale) {
logging.warn(`i18n was unable to find ${locale}.json.`);
}
_handleInvalidFileError(locale, err) {
logging.error(new errors.IncorrectUsageError({
err,

View file

@ -4,9 +4,9 @@ const I18n = require('./I18n');
class ThemeI18n extends I18n {
/**
* @param {objec} [options]
* @param {string} basePath - the base path for the translation directory (e.g. where themes live)
* @param {string} [locale] - a locale string
* @param {object} [options]
* @param {string} options.basePath - the base path for the translation directory (e.g. where themes live)
* @param {string} [options.locale] - a locale string
*/
constructor(options = {}) {
super(options);
@ -48,6 +48,7 @@ class ThemeI18n extends I18n {
logging.warn(`Theme translations file locales/${locale}.json not found.`);
}
}
_handleInvalidFileError(locale, err) {
logging.error(new errors.IncorrectUsageError({
err,