Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for the bug where the default language in global settings cannot be changed #350

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/TTFFont.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions src/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
4 changes: 2 additions & 2 deletions test/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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");
});
});

Expand Down