-
Notifications
You must be signed in to change notification settings - Fork 80
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
Cannot format a message without first setting the initial locale when open _error route #51
Comments
I also get the same error... |
Hey @aksenovdev and @AlexanderBelkevich 👋 It seems that when going to an error page, the |
@kaisermann I have this error without sapper, on clear svelte |
Would you be able to provide a repro project? |
I'm seeing the same issue, with sapper, on first load of a page. The first time I open the app in my browser I get this error, when reloading or even closing the browser & reoping the page everything works as expected. Can't reproduce in dev on a local machine, only when running as a google App Engine. |
Same issue here, this also happens in the included example in the repo. If you run the example and go to a non existent page, you will find the error popping up in the console.
|
Same issue here. Had to remove all translated $_ from the error page to fix it temporarily. Maybe someone has a better option. |
i was getting the same error until i used https://github.com/kaisermann/svelte-i18n/blob/master/docs/Locale.md#isloading |
As @jayk09 stated, the current solution is to use the |
I had the same issue, adding this worked for me:
Note that I have only one locale for now. |
Adding this code in the |
For everyone coming across this issue using svelte@next. Here is my solution for now. routes/$layout.svelte <script context="module">
// is not working atm for routes/* and on reload with snowpack
// export async function preload() {
// return waitLocale();
// }
</script>
<script>
import NavBar from "../components/navbar/Navbar.svelte";
import {
register,
t,
init,
getLocaleFromNavigator,
isLoading,
} from "svelte-i18n";
// note it's ending is .json, while the filename in static/ is .json.js
register("en", () => import("/lang/en.json"));
init({ initialLocale: getLocaleFromNavigator(), fallbackLocale: "en" });
</script>
{#if $isLoading}
Please wait...
{:else}
{$t("test")}
<NavBar />
<main>
<slot />
</main>
{/if} routes/index.svelte <script>
import { t } from "svelte-i18n";
</script>
{$t("test") static/lang/en.json.js export default {
test: "test",
}; |
Can you explain why can't we load it async instead of waiting for all the translations to be ready at this point? |
For me it was a problem that I use i18n-keys before they where actually initialized, so I needed to await the result: <script>
import {
register,
init,
_
} from 'svelte-i18n'
async function setup() {
register('en', () => import('@/i18n/en.json'))
return await Promise.allSettled([
// TODO: add some more stuff you want to init ...
init({ initialLocale: 'en', fallbackLocale: 'en' })
])
}
const setupResult = setup()
</script>
{#await setupResult}
<!-- <p>...show loading animation</p> -->
{:then}
<h1>{$_('setup.max_players')}</h1>
{:catch error}
<!-- <p style="color: red">{error.message}</p> -->
{/await} |
The best solution for me. Otherwise it will have too much duplicated code. |
Describe the bug
When I try open
_error
route with some translate in it or in_layout
, library throw errorLogs
To Reproduce
_error
OR_layout
({$_('title.index', { default: 'Sapper project template!' })}
, for example)Information about your project:
Browser: Chrome 82.0.4067.0
OS: Windows 10
svelte-i18n
version: latestBundler: Rollup
The text was updated successfully, but these errors were encountered: