diff --git a/src/TTFFont.js b/src/TTFFont.js index 6aa0937..eff3205 100644 --- a/src/TTFFont.js +++ b/src/TTFFont.js @@ -96,14 +96,14 @@ export default class TTFFont { * `lang` is a BCP-47 language code. * @return {string} */ - getName(key, lang = this.defaultLanguage || fontkit.defaultLanguage) { + getName(key, lang = this.defaultLanguage || fontkit.defaultLanguage()) { let record = this.name && this.name.records[key]; if (record) { // Attempt to retrieve the entry, depending on which translation is available: return ( record[lang] || record[this.defaultLanguage] - || record[fontkit.defaultLanguage] + || record[fontkit.defaultLanguage()] || record['en'] || record[Object.keys(record)[0]] // Seriously, ANY language would be fine || null diff --git a/src/base.js b/src/base.js index 1f9d40b..2723963 100644 --- a/src/base.js +++ b/src/base.js @@ -23,7 +23,12 @@ export function create(buffer, postscriptName) { throw new Error('Unknown font format'); }; -export let defaultLanguage = 'en'; +let _defaultLanguage = 'en'; + +export function defaultLanguage() { + return _defaultLanguage; +} + export function setDefaultLanguage(lang = 'en') { - defaultLanguage = lang; + _defaultLanguage = lang; }; diff --git a/test/i18n.js b/test/i18n.js index 81e1d1a..63ac329 100644 --- a/test/i18n.js +++ b/test/i18n.js @@ -23,7 +23,7 @@ describe('i18n', function () { it('can set global default language to "ar"', function () { fontkit.setDefaultLanguage('ar'); - assert.equal(fontkit.defaultLanguage, 'ar'); + assert.equal(fontkit.defaultLanguage(), 'ar'); }); it('font now has "ar" metadata properties', function () { @@ -37,7 +37,7 @@ describe('i18n', function () { it('can reset default language back to "en"', function () { fontkit.setDefaultLanguage(); - assert.equal(fontkit.defaultLanguage, "en"); + assert.equal(fontkit.defaultLanguage(), "en"); }); });