Code Monkey home page Code Monkey logo

Comments (4)

vthibault avatar vthibault commented on May 19, 2024

Hi, and thanks for your suggestion !

Apart from the breaking change, I see different problems with this implementation.

If the locale isn't defined, it will do the following :

table[""] = {};

I don't feel good with empty string as prop, so it implicates to set a default value to the locale (en ?) to avoid the problem.

It will also break people who wrote the set() before the locale() thinking there is no internal relations:

set({
  test: 'test',
  // ...
});
locale('xx');

And will certainly cause problem with asynchrone JSON loading and locale() updates during this time causing the table to be set in the wrong namespace.

My opinion on this one is too keep it verbose to avoid problems.

from frenchkiss.js.

ftonato avatar ftonato commented on May 19, 2024

Hmmm 🤔,

I don't like "verbose" things, but even if we assume a default value to locale based on browser language, see the below code, we will have problems with async JSON loading =(

let _locale = !languages[navigator.language]
  ? languages[navigator.language.substr(0, 2).toLowerCase()] ||
    'en',
  : languages[navigator.language];

from frenchkiss.js.

vthibault avatar vthibault commented on May 19, 2024

In my opinion, it's not up to this library to check the user language. All websites have different rules to determine it, and the browser language is most of the time the last verification they do, in the order :

  • hl query parameter.
  • fb_locale query parameter.
  • account language (session, cookie)
  • language folder in the url
  • language dns the url
  • browser language

If you really want something that doesn't lead to errors and don't duplicate commands it will be better to configure the table and the locale at the same time, only one function needed.

Something like (not implemented) :

frenchkiss.init({
  locale: 'en',
  fallback: 'fr',
  messages: {
    en: {
       test: 'test'
    },
    fr: {
       test: 'test'
    };
  }
});

from frenchkiss.js.

ftonato avatar ftonato commented on May 19, 2024

Yeah, I agree with you:

it's not up to this library to check the user language 👍

let maybe? = 'keep it verbose is the best approach to avoid problems.';

index

from frenchkiss.js.

Related Issues (12)

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.