Code Monkey home page Code Monkey logo

Comments (14)

kaisermann avatar kaisermann commented on July 26, 2024 1

Fixed on v2.0.1. Please, see https://github.com/kaisermann/svelte-i18n/wiki#setting-the-initial-locale to set the initial and fallback locales in a simpler way 😁

from svelte-i18n.

ralyodio avatar ralyodio commented on July 26, 2024 1

I'm downgrading until you figure out how to fix your bugs.

from svelte-i18n.

kaisermann avatar kaisermann commented on July 26, 2024

I wasn't very good of words while explaining what that prop does. The fallback locale is only used as a possible return value of getClientLocale. There's currently no way to define a default locale in the way you want. Going to work on this soon 😁

from svelte-i18n.

ralyodio avatar ralyodio commented on July 26, 2024

Change language in chrome. I get an error now and blank screen. IT now shows EN but if I choose DE (which I have translations for) I get an error.

import { locale, register, getClientLocale } from 'svelte-i18n'
import { de, fr, en } from './i18n'

// // Define a locale dictionary
// dictionary.set({
//   de,
//   fr,
//   en,
// })


// This is a store, so we can subscribe to its changes
locale.subscribe(() => {
  console.log('locale change')
})

// svelte-i18n exports a method to help getting the current client locale
locale.set(
  getClientLocale({
    // the fallback locale, if didn't find any
    fallback: 'en',
    // set to 'true' to check the 'window.navigator.language'
    navigator: true,
    // // set the key name to look for a locale on 'window.location.search'
    // // 'example.com?locale=en-US'
    // search: 'lang'
  }),
)

register('de', () => de)
register('fr', () => fr)
register('en', () => en)
// Set the current locale to en-US
// locale.set('en')

from svelte-i18n.

ralyodio avatar ralyodio commented on July 26, 2024

from svelte-i18n.

kaisermann avatar kaisermann commented on July 26, 2024

Can you provide a repro? It would help a lot to solve your issue 😁

For that example above: check the wiki link I sent you, it shows the correct way of adding dictionaries and setting the fallback locale.

  1. if you're importing/requiring all your dictionaries at build time, use the addMessages method. If you want to asynchronously load them, you can use register, but you will need to wait for the defined locale dictionary to load. See https://github.com/kaisermann/svelte-i18n/wiki#setting-the-initial-locale 😁
  2. Call setInitialLocale instead of locale.set and getClientLocale.
import { addMessages, setInitialLocale } from 'svelte-i18n'
import { de, fr, en } from './i18n'

// Add messages to each locale dictionary
addMessages('de', de)
addMessages('fr', fr)
addMessages('en', en)

// set the initial locale based on the user's 'navigator.language'
// and configure the fallback locale to english
setInitialLocale({
  fallback: 'en',
  navigator: true,
})

from svelte-i18n.

ralyodio avatar ralyodio commented on July 26, 2024

Uncaught Error: path is not a valid object path
at objectResolvePath (object-resolve-path.js:17)
at U (i18n.mjs:1)
at Object.q [as $_] (i18n.mjs:1)
at create_fragment$1 (Home.svelte:1)
at init (index.mjs:1346)
at new Home (Home.svelte:2)
at create_fragment (Router.svelte:168)
at init (index.mjs:1346)
at new Router (Router.svelte:158)
at create_fragment$r (Topnav.svelte:10)```


This is what I get. site is https://puump.com

from svelte-i18n.

kaisermann avatar kaisermann commented on July 26, 2024

Can you share a minimal reproduction of what you're doing in your project? It's kind of hard to know what's exactly happening just by that error message. Are you using message ids with special characters, such as -, @?

from svelte-i18n.

ralyodio avatar ralyodio commented on July 26, 2024

yes of course i have special characters. i use english as the key, as is common practice.

<p>{$_('Completely private, pay with Bitcoin. Cancel when you want.')}</p>

This worked fine the other day, but now it seems to throw an error.

from svelte-i18n.

kaisermann avatar kaisermann commented on July 26, 2024

For a shallow dictionary, using english as keys should be working. I'll rewrite all the tests in the following week, hopefully it'll cover your issues.

It will take less time to debug and fix your issue if you stop just demanding a fix and instead help me help you. Just be patient.

from svelte-i18n.

ralyodio avatar ralyodio commented on July 26, 2024

so are we supposed to use 2.0.3 or 1.1.2?

from svelte-i18n.

kaisermann avatar kaisermann commented on July 26, 2024

Keep using the version you're using for now. I'm already working on the v2 fixes and a migration guide from v1 to v2.

from svelte-i18n.

kaisermann avatar kaisermann commented on July 26, 2024

Version 2.1.0 was released. I've also updated the docs and made a quick migration guide from v1 to v2: https://github.com/kaisermann/svelte-i18n/wiki/Migration

Let me know if your issue is fixed after migrating.

from svelte-i18n.

ralyodio avatar ralyodio commented on July 26, 2024

working now! thank you.

from svelte-i18n.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.