Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
@shore/i18n
Advanced tools
A wrapper around some *i18next* functionality - encapsulating *namespaced* translations.
A wrapper around some i18next functionality - encapsulating namespaced translations.
Translation file ./de/translation.json
:
{
"english": "Englisch"
}
Translation file ./de/my-namespace.json
:
{
"Hello world!": "Hallo Welt!"
}
Application example:
import i18n from '@shore/i18n';
i18n.init({
locale: 'de',
...
})
.then(() => {
console.log(i18n.locale); // -> 'de'
console.log(i18n.t('english')); // -> 'Englisch'
return i18n.loadNamespace('my-namespace');
})
.then((i18nNamespaced) => {
console.log(i18nNamespaced.t('Hello world!')); // -> 'Hallo Welt!'
});
If i18next should not be bundled because the embedding page already made it globally available through window.i18n
and called init
on it, use:
import i18n from '@shore/i18n/no-bundled-i18next';
console.log(i18n.locale); // -> 'de'
i18n.loadNamespace('my-namespace')
.then((i18nNamespaced) => {
console.log(i18nNamespaced.t('Hello world!')); // -> 'Hallo Welt!'
});
If you want to conveniently use namespaced version of t
and exists
across modules:
// i18n.js
import i18n from '@shore/i18n/no-bundled-i18next';
const namespace = 'my-namespace';
export default i18n;
export function loadDefaultNamespace() {
return i18n.loadNamespace(namespace);
}
export const i18nNamespaced = i18n.useNamespace(namespace);
// my-module.js
import { i18nNamespaced as i18n } from './i18n';
export function helloWorld() {
return i18n.t('Hello World!');
}
// main.js
import { loadDefaultNamespace } from './i18n';
import { helloWorld } from './my-module';
loadDefaultNamespace().then(() => {
console.log(helloWorld()); // -> 'Hallo Welt!'
});
FAQs
A wrapper around some *i18next* functionality - encapsulating *namespaced* translations.
We found that @shore/i18n demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 15 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.