chore: rework i18n for js to avoid async and duplication#668
chore: rework i18n for js to avoid async and duplication#668mcdurdin wants to merge 1 commit intofeat/search-i18nfrom
Conversation
Moves the responsibility for determining locale fallback server-side, so that we can avoid async pollution and have just a single responsible module for locale fallback. Strings are injected into a <script> data element as JSON, reducing the number of network round trips. Test-bot: skip
User Test ResultsTest specification and instructions User tests are not required |
darcywong00
left a comment
There was a problem hiding this comment.
nice - this does make things cleaner!
| $localization = ''; | ||
| foreach($locales as $locale) { | ||
| if($localization != '') $localization .= ",\n"; | ||
| $localization .= "{ \"locale\": \"$locale\", \"strings\": " . file_get_contents(__DIR__ . "/../../locale/strings/$domain/$locale.json") . "}"; |
There was a problem hiding this comment.
Just wanted to confirm the folder structure for all the localized strings will be:
PHP (existing)
.../locale/strings/keyboards/ (for the main keyboards/ page)
.../locale/strings/keyboards/details/
.../locale/strings/keyboards/install/
.../locale/strings/keyboards/share/
JS (so far)
.../locale/strings/keyboard-search/
So we don't want to have the JS strings somewhere in /locale/strings/keyboards/?
There was a problem hiding this comment.
The JS paths in crowdin.yml would need to be updated.
I can do here or back on my base PR
# JS files
- source: /_includes/locale/strings/keyboard-search/en.json
dest: /js/search/en.json
translation: /_includes/locale/strings/keyboard-search/%locale%.json
languages_mapping:
locale:There was a problem hiding this comment.
There's a lot of munging on the "embed json i18n strings" for loop.
Would it be cleaner to wrap it in a Util.php function?
| * @param {string} domain | ||
| */ |
There was a problem hiding this comment.
| * @param {string} domain | |
| */ | |
| * @param {string} domain | |
| * @return {boolean} Status if domain was successfully loaded | |
| */ |
Moves the responsibility for determining locale fallback server-side, so that we can avoid async pollution and have just a single responsible module for locale fallback.
Strings are injected into a <script> data element as JSON, reducing the number of network round trips.
@darcywong00 happy to discuss this further as required
Test-bot: skip