dojo / i18n

:rocket: Dojo 2 - internationalization library.
http://dojo.io
Other
6 stars 19 forks source link

README feedback #117

Closed bryanforbes closed 6 years ago

bryanforbes commented 6 years ago
  1. Several of the TypeScript examples do not have code highlighting on them
  2. The following paragraph is weird:

    Once the default bundle is in place, any locale-specific messages are loaded by passing the default bundle to the i18n function. The locale bundles expose their messages on their default exports:

I think the first sentence should be moved after the code example. It would end up looking like this:


The locale bundles expose their messages on their default exports (in this case, nls/fr/common):

const messages = {
    hello: 'Bonjour',
    goodbye: 'Au revoir'
};
export default messages;

Once the default bundle is in place, any locale-specific messages are loaded by passing the default bundle to the i18n function. Using the previous example as the default bundle, any locale-specific messages are loaded as follows:


  1. Where does invalidate come from in the example demonstrating that feature?
  2. It might be a good idea to have an example showing the difference between systemLocale and locale.
  3. It would be a good idea to have an example showing how to use the data from cldr-json. Something that shows pulling in the info into specific locale bundles:
import likelySubtags from 'cldr-json/supplemental/likelySubtags';
import plurals from 'cldr-json/supplemental/plurals';

export default {
    locales: {
        fr: () => import('./fr/common')
    },
    messages: {
        cldr: {
            supplemental: { likelySubtags, plurals }
        }
    }
}
import numbers from 'cldr-json/main/fr/numbers';
import currencies from 'cldr-json/main/fr/currencies';

export default {
    cldr: {
        main: {
            numbers: {
                ...numbers.main.fr.numbers,
                currencies: currencies.main.fr.numbers.currencies
            }
        }
    }
}

And then using i18n() to pull in the locale bundles and then running loadCldrData() on the key:

import i18n, { Messages } from '@dojo/i18n/main';
import loadCldrData from '@dojo/i18n/cldr/load';
import bundle from 'nls/common';

i18n(bundle, 'fr').then(function (messages: Messages) {
    loadCldrData(messages.cldr);

    console.log(messages.hello); // "Bonjour"
    console.log(messages.goodbye); // "Au revoir"
});
  1. Can you pass a locale-specific bundle to getMessageFormatter or formatMessage? If so, should we show an example doing that?
  2. It might be helpful to mention loadCldrData again in the date and number formatting section.
dasa commented 6 years ago

I find it confusing that the first example shows fr coming from /common, but ar and ar-JO are loaded from /main.

maier49 commented 6 years ago
  1. The table of contents links to ICU Message Formatting, but not Message Formatting, of which ICU Message Formatting is a (the only) subsection.
  2. Similar to invalidate, where do getCachedMessages and setLocaleMessages come from in their examples?
  3. Under the "Code Style" section, "the projects package.json" should be " the project's package.json"
  4. Under "Changing the Root Locale and Observing Locale Changes", the Observers link just links to the @dojo/shim package. It might be more useful to at least link to the section on Observables, or the spec, which is what the shim README points to anyways.
mwistrand commented 6 years ago

@maier49 observeLocale was recently changed to accept callbacks rather than observers, and the README has been updated accordingly.

@bryanforbes The i18n function (from @dojo/i18n/i18n) does not check message bundles for CLDR data. Users could add something like the following to the top of every bundle that needs ICU message formatting, but I would not recommend it:

import loadCldrData from '@dojo/i18n/cldr/load';
import likelySubtags from 'cldr-json/supplemental/likelySubtags';
import plurals from 'cldr-json/supplemental/plurals';

loadCldrData(likelySubtags);
loadCldrData(plurals);

export default {
    locales: { /* ... */ },
    messages: { /* ... */ }
}

However, we should probably add a note explaining that some of this heavy-lifted is handled by the build in Dojo 2 applications.