Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot format a message without first setting the initial locale when open _error route

See original GitHub issue

Describe the bug When I try open _error route with some translate in it or in _layout, library throw error

Logs image

To Reproduce

  1. Clone i18n example repo
  2. Add some translate in _error OR _layout ({$_('title.index', { default: 'Sapper project template!' })}, for example)
  3. Open dont exist page (http://localhost:3000/ds)

Information about your project:

  • Browser: Chrome 82.0.4067.0

  • OS: Windows 10

  • svelte-i18n version: latest

  • Bundler: Rollup

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:15 (3 by maintainers)

github_iconTop GitHub Comments

tw1t611commented, Jan 21, 2021

For everyone coming across this issue using svelte@next. Here is my solution for now. Note that this is not prerendered at build-time.


<script context="module">
  // is not working atm for routes/* and on reload with snowpack
  // export async function preload() {
  //   return waitLocale();
  // }

  import NavBar from "../components/navbar/Navbar.svelte";

  import {
  } 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" });

{#if $isLoading}
  Please wait...
    <NavBar />
      <slot />


  import { t } from "svelte-i18n";



export default {
  test: "test",
kevinXmichaelcommented, Dec 13, 2021

For me it was a problem that I use i18n-keys before they where actually initialized, so I needed to await the result:

    import {
    } 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()

{#await setupResult}
	<!-- <p> loading animation</p> -->
{:catch error}
	<!-- <p style="color: red">{error.message}</p> -->
Read more comments on GitHub >

github_iconTop Results From Across the Web

that's some error regarding svelte-i18n follow this instructions ...
Cannot format a message without first setting the initial locale. :( that's some error regarding svelte-i18n follow this instructions to make ...
Read more >
Spring framework: No message found under code for locale
In general such issue appears not because of non-existence locale, but because MessageBundle is configured improperly.
Read more >
How to Localize a Svelte App with svelte-i18n | Phrase
Walkthrough of the starter project code; Installing and setting up the svelte-i18n library; Dynamic, per-locale translation file loading ...
Read more >
Locale settings are not right. How can I reset them? - Ask Ubuntu
Using the fallback 'C' locale. The locale command produces error messages locale: Cannot set LC_CTYPE to default locale: No such file or directory...
Read more >
Svelte i18n Internationalization: how to localize a Svelte app
This Svelte localization tutorial explains how to setup and utilize ... an error that it cannot load without an initial locale being set....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found