-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SX Design: merge translations when FBT instance already exists
This change fixes a support for applications that are already using FBT. The problem was that FBT uses a singleton pattern and doesn't work well when you are calling FBT `init` (or `registerTranslations`) inside another `init` because it gets overwritten. Applications not using FBT work without any issues. PR facebook/fbt@d05d44f adds necessary changes to FBT and this change implements them in SX Design. Closes: #2205
- Loading branch information
1 parent
a2e0b4f
commit 4001a56
Showing
11 changed files
with
101 additions
and
77 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"fb-locale": "es-mx", | ||
"fb-locale": "es-MX", | ||
"translations": { | ||
"XKQt/WzTgsZemYhMzTVAuw==": { | ||
"tokens": [], | ||
|
This file contains 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 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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"en-us": {} | ||
"en-US": {} | ||
} |
This file contains 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 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 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 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 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 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 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,34 @@ | ||
// @flow | ||
|
||
import { invariant } from '@adeira/js'; | ||
|
||
import type { SupportedLocales } from './constants'; | ||
|
||
type TranslationStr = string; | ||
|
||
// {locale: {hash: translation}} | ||
type TranslationDict = { | ||
[locale: string]: { [hashKey: string]: TranslationStr }, | ||
}; | ||
|
||
export default function getFbtTranslationsForLocale(locale: SupportedLocales): TranslationDict { | ||
// TODO: support translations lazy loading | ||
const supportedLocales = { | ||
'ar-AR': require('../translations/out/ar-AR.json'), | ||
'ar-AR-u-nu-arab': require('../translations/out/ar-AR.json'), | ||
'cs-CZ': require('../translations/out/cs-CZ.json'), | ||
'en-US': require('../translations/out/en-US.json'), | ||
'es-MX': require('../translations/out/es-MX.json'), | ||
'no-NO': require('../translations/out/no-NO.json'), | ||
'ru-RU': require('../translations/out/ru-RU.json'), | ||
'uk-UA': require('../translations/out/uk-UA.json'), | ||
}; | ||
|
||
invariant( | ||
supportedLocales[locale] != null, | ||
'Cannot get FBT translation for locale "%s" because it doesn\'t exist.', | ||
locale, | ||
); | ||
|
||
return supportedLocales[locale]; | ||
} |