Skip to content

Commit 0573a0c

Browse files
"fixed" localization issue
1 parent 2feeda5 commit 0573a0c

File tree

7 files changed

+46
-61
lines changed

7 files changed

+46
-61
lines changed

CONTRIBUTING.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ For translations, the target language of this site is English, so you should bas
99
under [/src/Assets/L10N](/src/Assets/L10N) there are JSON files for the existing supported languages.
1010
For adding your own, copy the [en-us.json](/src/Assets/L10N/en-us.json) file and rename it with the correct locale code for the targeted language. (e.g Japanese would be `ja.json`)
1111

12-
To have the language work on the site, add the language translation to the JSON file, then go to [main.ts](/src/main.ts#L29) and add a new line.
12+
To have the language work on the site, add the language translation to the JSON file, then go to [main.ts](/src/main.ts#L27) and add a new line.
1313
The line should look like this (using Japanese as an example):
14-
```register('ja', () => import('./Assets/L10N/ja.json'));```
14+
`addMessages('ja', await import('./L10N/ja.json') as never);`
1515

1616
Which boils down to:
17-
```register('language-code', () => import('./Assets/L10N/language-code.json'));```
17+
`addMessages('language-code', await import('./L10N/language-code.json') as never);`
1818

1919
To find a list of Language Codes using Firefox, go to `about:preferences`, search `language`, and choose `Choose your preferred language for displaying pages`, then find your language and look at the code (in the square brackets)
2020

package-lock.json

+6-39
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "project-lodestone-website",
33
"private": true,
4-
"version": "1.0.6",
4+
"version": "1.0.7",
55
"type": "module",
66
"scripts": {
77
"dev": "vite",
@@ -24,7 +24,7 @@
2424
"vite": "^6.2.2"
2525
},
2626
"dependencies": {
27-
"@team-lodestone/lodestone-ui": "^1.3.4",
27+
"@team-lodestone/lodestone-ui": "^1.3.5",
2828
"svelte-i18n": "^4.0.1"
2929
}
3030
}

src/App.svelte

-2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,4 @@
4747
<ButtonLink class="button topbarButton" href="https://github.com/team-lodestone/team-lodestone.github.io" title={$t('footer.buttons.openSource.title')}>{$t('footer.buttons.openSource.text')}</ButtonLink>
4848
<ButtonLink class="button topbarButton" href="https://team-lodestone.github.io/Documentation/Team" title={$t('footer.buttons.openTeam.title')}>{$t('footer.buttons.openTeam.text')}</ButtonLink>
4949
</Footer>
50-
{:else}
51-
<h1>Loading</h1>
5250
{/if}

src/Components/Dialogs/LanguageDialog.svelte

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import {Dialog, DropDownBox} from "@team-lodestone/lodestone-ui";
33
import { locales, locale } from 'svelte-i18n'
44
import { _ as t } from 'svelte-i18n'
5-
import { initL10N } from '../../main';
5+
import { setupL10N } from '../../main';
66
77
let dialog: Dialog;
88
@@ -13,7 +13,7 @@
1313
function setLanguage(e: Event): void {
1414
// UNTESTED (can't test until new language is added)
1515
localStorage.setItem("language", (e.currentTarget as HTMLSelectElement).value)
16-
initL10N();
16+
setupL10N();
1717
}
1818
</script>
1919

src/main.ts

+32-12
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,19 @@ export const url = "https://team-lodestone.github.io"
1818
// endregion
1919

2020
// region l10n
21-
import {getLocaleFromNavigator, init, register} from 'svelte-i18n'
21+
import { getLocaleFromNavigator, init, addMessages, register } from 'svelte-i18n';
22+
import { initLUILanguages } from "@team-lodestone/lodestone-ui";
2223

23-
// has to have US bc browser returns en-US instead of en
24-
register('en-US', async () => await import('./Assets/L10N/en-us.json'));
25-
register('fr', async () => await import('./Assets/L10N/fr.json'));
26-
register('ru', async () => await import('./Assets/L10N/ru.json'));
24+
const initL10N = async () => {
25+
// has to have US bc browser returns en-US instead of en
26+
// also use addMessages over register to avoid flash of content while loading other language during switch.
27+
addMessages('en-US', (await import('./Assets/L10N/en-us.json')) as never);
28+
addMessages('fr', (await import('./Assets/L10N/fr.json')) as never);
29+
addMessages('ru', (await import('./Assets/L10N/ru.json')) as never);
30+
31+
// setup l10n
32+
await setupL10N();
33+
}
2734

2835
const getLanguage = (): string | null => {
2936
const lang = localStorage.getItem("language");
@@ -32,15 +39,28 @@ const getLanguage = (): string | null => {
3239
else return getLocaleFromNavigator();
3340
}
3441

35-
export const initL10N = async () => await init({ fallbackLocale: 'en-US', initialLocale: getLanguage(), warnOnMissingMessages: true });
36-
37-
initL10N();
42+
export const setupL10N = async () => {
43+
await initLUILanguages({ fallbackLocale: 'en-US', initialLocale: getLanguage(), warnOnMissingMessages: true });
44+
await init({ fallbackLocale: 'en-US', initialLocale: getLanguage(), warnOnMissingMessages: true });
45+
}
3846
// endregion
3947

48+
4049
// region app
41-
const app = mount(App, {
42-
target: document.getElementById('app')!,
43-
})
50+
let app: { $set?: any, $on?: any } | undefined = undefined;
51+
52+
async function initApp() {
53+
await initL10N();
54+
55+
return mount(App, {
56+
target: document.getElementById('app')!,
57+
})
58+
}
59+
60+
// if we don't wait for initL10N we get locale loading race condition afaik
61+
initApp().then((mounted) => {
62+
app = mounted;
63+
});
4464

45-
export default app
65+
export default app;
4666
// endregion

vite.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ export default defineConfig({
1616
}),
1717
],
1818
server: {
19-
allowedHosts: ['localhost', '127.0.0.1', 'team-lodestone.github.io', 'b6e7-146-70-211-58.ngrok-free.app'],
19+
allowedHosts: ['localhost', '127.0.0.1', 'team-lodestone.github.io'],
2020
}
2121
})

0 commit comments

Comments
 (0)