New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use @intlify/core
in NodeJS
#1663
Comments
Thank you for your feedback! We are planning to migrate There is no documentation, but here are some real world packages where
|
My example code of using // i18n.js
import {
createCoreContext,
number,
translate,
} from '@intlify/core';
import datetimeFormats from './datetimeFormats.js';
import numberFormats from './numberFormats.js';
import pluralRules from './pluralRules.js';
const messages = {};
// load messages
const contexts = new Map();
export function i18n(locale) {
if (!contexts.has(locale)) {
contexts.set(locale, createCoreContext({
locale: locale,
messages,
datetimeFormats,
numberFormats,
pluralRules,
}));
}
const i18nContext = contexts.get(locale);
return {
t(key, ...args) {
return translate(i18nContext, key, ...args);
},
n(value, ...args) {
return number(i18nContext, value, ...args);
},
};
} Usage: bot.use(async (ctx, next) => {
// make t and n available on context
Object.assign(ctx, i18n(ctx.user.locale));
return next();
}); This allow me to share almost all translation logic between vue app and server side bot related code. |
Clear and concise description of the problem
Could you please add code samples and/or documentation how to use
@intlify/core
in bare NodeJS app.Suggested solution
Code samples or documentation or tests in the repo https://github.com/intlify/vue-i18n-next/tree/master/packages/core
Alternative
No response
Additional context
It would be helpful to use the same i18n system in
vue
app and server side code.Validations
The text was updated successfully, but these errors were encountered: