Skip to content
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 configure a custom directory #1248

Open
2h-Lin opened this issue Dec 11, 2024 · 0 comments
Open

How to configure a custom directory #1248

2h-Lin opened this issue Dec 11, 2024 · 0 comments

Comments

@2h-Lin
Copy link

2h-Lin commented Dec 11, 2024

I am using the vue framework, and now my i18n directory is like this
image

The index.js file is used to set the global language. The code is below

`import Vue from "vue";
import VueI18n from "vue-i18n";

Vue.use(VueI18n);

function getMessages(modules, languages) {
let messages = {};
languages.forEach(lang => {
messages[lang] = {};
});

modules.forEach(moduleName => {
languages.forEach(async lang => {
try {
let { default: obj } = await import("./" + ${moduleName}/${lang}.json);
// { en: { base: { } }, zh: { base: {} }}
!messages[lang][moduleName] && (messages[lang][moduleName] = {});
Object.assign(messages[lang][moduleName], obj);
} catch (e) {
console.warn(e.message);
}
});
});
console.log(messages);
return messages;
}

const modules = ["base", "studyPayment"]; // 模块数组
const languages = ["en", "zh"]; // 语言数组
let messages = getMessages(modules, languages);

const i18n = new VueI18n({
locale: localStorage.getItem("lang") || "zh", // 设置默认语言环境
messages
});

// 设置Element语言
ELEMENT.locale(ELEMENT.lang[localStorage.getItem("lang") || "zh"]);

export default i18n;`

I want to use i18n-ally. What configuration do I need? I have tried many times but it doesn't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant