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

feat(unplugin-vue-i18n): provide list of supported locales #251

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/unplugin-vue-i18n/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,7 @@ async function generateBundleResources(
}
) {
const codes = []
const locales = []
for (const res of resources) {
debug(`${res} bundle loading ...`)

Expand Down Expand Up @@ -790,6 +791,7 @@ async function generateBundleResources(

debug('generated code', code)
codes.push(`${JSON.stringify(name)}: ${code}`)
locales.push(name)
}
}

Expand All @@ -815,7 +817,8 @@ const mergeDeep = (target, ...sources) => {

export default mergeDeep({},
${codes.map(code => `{${code}}`).join(',\n')}
);`
);
export const SUPPORTED_LOCALES = ${JSON.stringify(locales)};`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We prefer to support loaded locales with the API implemented in vue-i18n, not with constants exported in virtual modules.

vue-i18n keeps the locale internally. If the API is provided on the virtual module side, locales conflicts may occur.

}

async function getCode(
Expand Down