Migration guide - 3.x.x -> 4.x.x #24
Replies: 2 comments
-
So this is what I got so far and what I had to do, to make it run again 👍 Migration Guide 3.x.x -> 4.x.xUsageSetting upYou have to instantiate an Beforeimport I18n from 'i18n-js';
import english from './en.json';
import yoruba from './yo.json';
...
I18n.locale = 'en';
I18n.fallbacks = true;
I18n.translations = {
en: english,
yo: yoruba,
}; Afterimport I18n from 'i18n-js';
import english from './en.json';
import yoruba from './yo.json';
...
const i18n = new I18n(
// Translations
{
en: english,
yo: yoruba,
},
{
locale: "en",
enableFallback: true,
}
); Translating messagesYou have to use the instantiated object now. Beforeimport I18n from 'i18n-js';
...
I18n.t('main.welcome'); Afterimport I18n from 'i18n-js';
...
export const i18n = new I18n(...); import { i18n } from '.../i18n.ts';
...
i18n.t('main.welcome'); toCurrencyRenamed to BeforeI18n.toCurrency(amount / 100, options); After// i18n is the initialized object, see "Setting up"
i18n.numberToCurrency(amount / 100, options); TypesToCurrencyOptionsChanged to Beforeimport { ToCurrencyOptions } from 'i18n-js';
...
const options: ToCurrencyOptions = {
delimiter: '.',
separator: ',',
precision: 4,
format: '%n %u',
}; Afterimport { NumberToCurrencyOptions } from 'i18n-js/typings/typing';
...
const options: NumberToCurrencyOptions = {
delimiter: '.',
separator: ',',
precision: 4,
format: '%n %u',
negativeFormat: '-%n %u',
roundMode: 'default',
significant: false,
stripInsignificantZeros: false,
raise: false,
unit: '',
}; TestingMocking with jestCheck out jest documentation about mocking node modules. Before
export default {
locale: 'en',
t: (translation) => translation,
numberToCurrency: jest.fn(),
currentLocale: () => 'yo',
} After
export const I18n = jest.fn().mockImplementation(() => {
return {
locale: 'yo',
t: (translation) => translation,
numberToCurrency: jest.fn(),
};
}); |
Beta Was this translation helpful? Give feedback.
-
I added a slim migration guide to the main repo as well. https://github.com/fnando/i18n-js/blob/main/MIGRATING_FROM_V3_TO_V4.md |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hej there!
At first: Thanks for keeping this project going! 👍 👍 🚀
Situation:
We updated i18n-js from
3.9.2
to4.0.2
and tried to look up for changes or alternatively a migration guide. But I did not found any.Question:
Is there any?
If not, maybe I can add some sentences to the
readme
as pull request? Wdyt?Beta Was this translation helpful? Give feedback.
All reactions