-
-
Notifications
You must be signed in to change notification settings - Fork 155
[core] i18n: Fresh Start #1074
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
Open
confused-Techie
wants to merge
27
commits into
master
Choose a base branch
from
localization-ct
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[core] i18n: Fresh Start #1074
Changes from 12 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
40efe0b
Taking another shot at i18n
confused-Techie 7449b44
Load core locales during initialization
confused-Techie 9b9094c
UI translations, context-menu translations
confused-Techie 9f47be8
Menu item translations, cleanup auto-translations
confused-Techie 5c3b47a
Stop using `atom` global
confused-Techie 431d802
Update specs to ensure they pass
confused-Techie d73cd15
Localize: Settings Title & Description
confused-Techie b7bd819
Add tests
confused-Techie 977f1bd
Add LocaleLabel translation tests to context-menu and manus
confused-Techie 0807084
Fix errors in tests
confused-Techie 6381419
Update `pulsar.en.cson` with new format
confused-Techie 0783bb8
Properly set fallback locale
confused-Techie e46ffba
Merge branch 'master' into localization-ct
confused-Techie 40f84c0
Ensure context menu submenus are translated
confused-Techie 2e1bc28
Fix tests
confused-Techie 83597c5
Merge branch 'master' into localization-ct
confused-Techie 78c7584
Ensure we pass the correct parameters to `I18n.ShouldIncludeLocale`
confused-Techie a84d5ae
Support `LocaleLabel`s in settings schema `enum.description`
confused-Techie 45e7da7
Merge branch 'master' into localization-ct
confused-Techie 501e482
Cache formatters to speed up translations
confused-Techie 625afec
Update src/config-schema.js
confused-Techie b868eb9
camelCase `localeNegotation`
confused-Techie df9835a
camelCase and rename `ShouldInlcudeLocale` => `shouldIncludeLocalePar…
confused-Techie dbb4cd0
camelCase `DoLocalesMatch` => `doLocalesMatch`
confused-Techie 7270d04
Always return the original keyPath on translation failure
confused-Techie 7ee0c4a
Merge branch 'master' into localization-ct
confused-Techie a815440
Removed `translateLabel` specific fallback, as `translate` accounts f…
confused-Techie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'pulsar': { | ||
'config': { | ||
'excludeVcsIgnoredPaths': { | ||
'title': 'Exclude VCS Ignored Paths' | ||
} | ||
} | ||
'menu': { | ||
'settings-view:view-installed-packages': 'Open Package Manager' | ||
} | ||
'context-menu': { | ||
'core:undo': 'Undo' | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
'commandPaletteView': { | ||
'emptyMessage': 'No matches found' | ||
'matchingTags': 'matching tags: ' | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,241 @@ | ||
const I18n = require("../src/i18n.js"); | ||
|
||
describe("I18n", () => { | ||
let i18n; | ||
|
||
beforeEach(() => { | ||
const { resourcePath } = atom.getLoadSettings(); | ||
i18n = new I18n({ | ||
config: atom.config | ||
}); | ||
i18n.initialize({ resourcePath }); | ||
}); | ||
|
||
describe("Handles Locales logic", () => { | ||
it("Locale Lookup Filtering Fallback Pattern Array: Follows RFC4647", () => { | ||
const primaryLocale = "es-MX"; | ||
const priorityListLocale = [ | ||
"zh-Hant-CN-x-private1-private2", | ||
"en-US" | ||
]; | ||
const fallbackSet = I18n.LocaleNegotiation(primaryLocale, priorityListLocale); | ||
|
||
expect(Array.from(fallbackSet)).toEqual([ | ||
"es-MX", | ||
"es", | ||
"zh-Hant-CN-x-private1-private2", | ||
"zh-Hant-CN-x-private1", | ||
"zh-Hant-CN", | ||
"zh-Hant", | ||
"zh", | ||
"en-US", | ||
"en" | ||
]); | ||
}); | ||
|
||
it("Locale Lookup Filtering Fallback Pattern Array: Excludes duplicates from hardcoded fallback", () => { | ||
const primaryLocale = "en-US"; | ||
const priorityListLocale = [ "es-MX" ]; | ||
const fallbackSet = I18n.LocaleNegotiation(primaryLocale, priorityListLocale); | ||
|
||
expect(Array.from(fallbackSet)).toEqual([ | ||
"en-US", | ||
"en", | ||
"es-MX", | ||
"es" | ||
]); | ||
}); | ||
|
||
it("Accurately determines if Locale Should be included when it should", () => { | ||
const primaryLocale = "en-US"; | ||
const priorityListLocale = [ "es-MX" ]; | ||
const questionedLocale = "en"; | ||
const shouldBeIncluded = I18n.ShouldIncludeLocale(questionedLocale, primaryLocale, priorityListLocale); | ||
expect(shouldBeIncluded).toEqual(true); | ||
}); | ||
|
||
it("Accurately determines if Locale Should be included when it shoudln't", () => { | ||
const primaryLocale = "zh-Hant"; | ||
const priorityListLocale = [ "es-MX" ]; | ||
const questionedLocale = "ja-JP"; | ||
const shouldBeIncluded = I18n.ShouldIncludeLocale(questionedLocale, primaryLocale, priorityListLocale); | ||
expect(shouldBeIncluded).toEqual(false); | ||
}); | ||
|
||
it("Accurately determines if Locale should be included when the locale is the hardcoded fallback", () => { | ||
const primaryLocale = "zh-Hant"; | ||
const priorityListLocale = [ "es-MX" ]; | ||
const questionedLocale = "en"; | ||
const shouldBeIncluded = I18n.ShouldIncludeLocale(questionedLocale, primaryLocale, priorityListLocale); | ||
expect(shouldBeIncluded).toEqual(true); | ||
}); | ||
|
||
it("Can determine if basic locales match", () => { | ||
const want = "en-US"; | ||
const have = "en-US"; | ||
expect(I18n.DoLocalesMatch(want, have)).toEqual(true); | ||
}); | ||
|
||
it("Can determine if wildcard locales match", () => { | ||
const want = "en-*"; | ||
const have = "en-US"; | ||
expect(I18n.DoLocalesMatch(want, have)).toEqual(true); | ||
}); | ||
|
||
it("Can determine if locales do not match", () => { | ||
const want = "en-US"; | ||
const have = "ja-JP"; | ||
expect(I18n.DoLocalesMatch(want, have)).toEqual(false); | ||
}); | ||
}); | ||
|
||
describe("Crafts strings object correctly", () => { | ||
it("Properly adds locale key", () => { | ||
i18n.addStrings({ | ||
example: { | ||
stringKey: "String Value" | ||
} | ||
}, "en-US"); | ||
|
||
expect(i18n.strings.example.stringKey).toEqual({ | ||
"en-US": "String Value" | ||
}); | ||
}); | ||
|
||
it("Handles deep objects", () => { | ||
i18n.addStrings({ | ||
example: { | ||
deepExampleKey: { | ||
stringKey: "String Value" | ||
} | ||
} | ||
}, "en-US"); | ||
|
||
expect(i18n.strings.example.deepExampleKey.stringKey).toEqual({ | ||
"en-US": "String Value" | ||
}); | ||
}); | ||
|
||
it("Adds new locales to existing objects", () => { | ||
i18n.addStrings({ | ||
example: { | ||
stringKey: "Hello Pulsar" | ||
} | ||
}, "en-US"); | ||
i18n.addStrings({ | ||
example: { | ||
stringKey: "Hola Pulsar" | ||
} | ||
}, "es-MX"); | ||
|
||
expect(i18n.strings.example.stringKey).toEqual({ | ||
"en-US": "Hello Pulsar", | ||
"es-MX": "Hola Pulsar" | ||
}); | ||
}); | ||
|
||
it("Adds new locale to object", () => { | ||
i18n.addStrings({ | ||
example: { | ||
stringKey: "Hello Pulsar" | ||
} | ||
}, "en-US"); | ||
|
||
i18n.addString("example.stringKey", "Hola Pulsar", "es-MX"); | ||
|
||
expect(i18n.strings.example.stringKey).toEqual({ | ||
"en-US": "Hello Pulsar", | ||
"es-MX": "Hola Pulsar" | ||
}); | ||
}); | ||
}); | ||
|
||
describe("Is able to translate properly", () => { | ||
|
||
beforeEach(() => { | ||
const primary = "es-MX"; | ||
const priorityListLocale = [ "zh-Hant" ]; | ||
i18n.localeFallbackList = I18n.LocaleNegotiation(primary, priorityListLocale); | ||
}); | ||
|
||
it("Returns the proper string based on user setting", () => { | ||
i18n.addStrings({ | ||
example: { | ||
stringKey: "Hello Pulsar" | ||
} | ||
}, "en"); | ||
|
||
i18n.addStrings({ | ||
example: { | ||
stringKey: "Hola Pulsar" | ||
} | ||
}, "es-MX"); | ||
|
||
expect(i18n.t("example.stringKey")).toEqual("Hola Pulsar"); | ||
}); | ||
|
||
it("Handles ICU MessageFormat Replacements", () => { | ||
i18n.addStrings({ | ||
example: { | ||
stringKey: "Hello {value}" | ||
} | ||
}, "en"); | ||
|
||
expect(i18n.t("example.stringKey", { value: "confused-Techie" })).toEqual( | ||
"Hello confused-Techie" | ||
); | ||
}); | ||
|
||
it("Handles namespace translations", () => { | ||
i18n.addStrings({ | ||
example: { | ||
stringKey: "Hello Pulsar" | ||
} | ||
}, "en"); | ||
|
||
const t = i18n.getT("example"); | ||
|
||
expect(t.t("stringKey")).toEqual("Hello Pulsar"); | ||
}); | ||
}); | ||
|
||
describe("Translates LocaleLabels", () => { | ||
it("Identifies a LocaleLabel", () => { | ||
const str1 = "%this-is-a-locale-label%"; | ||
const str2 = "this-is-not-a-locale-label"; | ||
const str3 = "%nor-is-this"; | ||
const str4 = "%or-%this"; | ||
|
||
expect(i18n.isAutoTranslateLabel(str1)).toEqual(true); | ||
expect(i18n.isAutoTranslateLabel(str2)).toEqual(false); | ||
expect(i18n.isAutoTranslateLabel(str3)).toEqual(false); | ||
expect(i18n.isAutoTranslateLabel(str4)).toEqual(false); | ||
}); | ||
|
||
it("Successfully translates a LocaleLabel", () => { | ||
const primary = "es-MX"; | ||
const priorityListLocale = [ "zh-Hant" ]; | ||
i18n.localeFallbackList = I18n.LocaleNegotiation(primary, priorityListLocale); | ||
|
||
i18n.addStrings({ | ||
example: { | ||
stringKey: "Hello Pulsar" | ||
} | ||
}, "en"); | ||
|
||
const localeLabel = "%example.stringKey%"; | ||
|
||
expect(i18n.translateLabel(localeLabel)).toEqual("Hello Pulsar"); | ||
}); | ||
|
||
it("Falls back to the original label if unable to translate", () => { | ||
const primary = "es-MX"; | ||
const priorityListLocale = [ "zh-Hant" ]; | ||
i18n.localeFallbackList = I18n.LocaleNegotiation(primary, priorityListLocale); | ||
|
||
const localeLabel = "%example.stringKey%"; | ||
|
||
expect(i18n.translateLabel(localeLabel)).toEqual("%example.stringKey%"); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.