What is @intlify/core-base?
@intlify/core-base is a core library for internationalization (i18n) in JavaScript applications. It provides essential functionalities for handling translations, message formatting, and locale management, making it easier to build multilingual applications.
What are @intlify/core-base's main functionalities?
Basic Translation
This feature allows you to define translations for different locales and switch between them. The code sample demonstrates how to create a context with messages in English and French, and how to switch the locale to get the translated message.
const { createCoreContext, translate } = require('@intlify/core-base');
const ctx = createCoreContext({
locale: 'en',
messages: {
en: {
hello: 'Hello, world!'
},
fr: {
hello: 'Bonjour, le monde!'
}
}
});
console.log(translate(ctx, 'hello')); // Output: Hello, world!
ctx.locale = 'fr';
console.log(translate(ctx, 'hello')); // Output: Bonjour, le monde!
Message Formatting
This feature allows you to use placeholders in your messages and replace them with dynamic values. The code sample shows how to define a message with a placeholder and provide a value for it during translation.
const { createCoreContext, translate } = require('@intlify/core-base');
const ctx = createCoreContext({
locale: 'en',
messages: {
en: {
greeting: 'Hello, {name}!'
}
}
});
console.log(translate(ctx, 'greeting', { name: 'Alice' })); // Output: Hello, Alice!
Locale Management
This feature provides the ability to manage the current locale and fallback locales. The code sample demonstrates how to set and get the current locale and how to define a fallback locale.
const { createCoreContext } = require('@intlify/core-base');
const ctx = createCoreContext({
locale: 'en',
fallbackLocale: 'fr',
messages: {
en: {
hello: 'Hello, world!'
},
fr: {
hello: 'Bonjour, le monde!'
}
}
});
console.log(ctx.locale); // Output: en
ctx.locale = 'fr';
console.log(ctx.locale); // Output: fr
Other packages similar to @intlify/core-base
i18next
i18next is a popular internationalization framework for JavaScript. It offers a wide range of features including translation, pluralization, and interpolation. Compared to @intlify/core-base, i18next has a larger ecosystem with plugins and integrations for various frameworks.
react-intl
react-intl is a library specifically designed for React applications. It provides components and APIs for formatting dates, numbers, and strings, and for handling translations. While @intlify/core-base is more general-purpose, react-intl is tailored for React, making it easier to use in React projects.
vue-i18n
vue-i18n is an internationalization plugin for Vue.js. It offers similar functionalities to @intlify/core-base but is specifically designed for Vue.js applications. It integrates seamlessly with Vue components and provides a simple API for managing translations and locales.
v11.0.0-beta.0 (2024-11-14T15:42:34Z)
This changelog is generated by GitHub Releases
<!-- Release notes generated using configuration in .github/release.yml at v11.0.0-beta.0 -->
What's Changed
💥 Breaking Changes
- feat!: deprecate Legacy API mode by @kazupon in https://github.com/intlify/vue-i18n/pull/2016
⚡ Improvement Features
- fix:
tm
function should accept DefineLocaleMessage
key type by @BobbieGoede in https://github.com/intlify/vue-i18n/pull/2014
📝️ Documentations
- Change config prop for quasar flags by @chrissyast in https://github.com/intlify/vue-i18n/pull/2003
- docs: Pluralization Page by @Sammuel09 in https://github.com/intlify/vue-i18n/pull/1998
- docs: fix composition section by @Sammuel09 in https://github.com/intlify/vue-i18n/pull/2008
- fix(docs): correct output in composition api example by @pejeio in https://github.com/intlify/vue-i18n/pull/2012
- docs: not use deprecated api by @kazupon in https://github.com/intlify/vue-i18n/pull/2013
New Contributors
- @chrissyast made their first contribution in https://github.com/intlify/vue-i18n/pull/2003
- @Sammuel09 made their first contribution in https://github.com/intlify/vue-i18n/pull/1998
- @pejeio made their first contribution in https://github.com/intlify/vue-i18n/pull/2012
Full Changelog: https://github.com/intlify/vue-i18n/compare/v10.0.4...v11.0.0-beta.0