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

refactor: add Vite compatibility when lazy loading #1084

Merged
merged 14 commits into from
Mar 4, 2021
Prev Previous commit
Next Next commit
use file as locale key
  • Loading branch information
pi0 committed Mar 3, 2021
commit 10db80d387957c165ff1e611bf03a0a71ed052e0
2 changes: 1 addition & 1 deletion src/templates/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ for (const [key, value] of Object.entries(options)) {

<% if (options.langDir) { %>
export const ASYNC_LOCALES = {
<%= options.locales.map(l => `'${l.code}': () => import('../${relativeToBuild(options.langDir, l.file)}' /* webpackChunkName: "lang-${l.file}" */)`).join(',\n ') %>
<%= options.locales.map(l => `'${l.file}': () => import('../${relativeToBuild(options.langDir, l.file)}' /* webpackChunkName: "lang-${l.file}" */)`).join(',\n ') %>
rchl marked this conversation as resolved.
Show resolved Hide resolved
}
<% } %>
2 changes: 1 addition & 1 deletion src/templates/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export async function loadLanguageAsync (context, locale) {
}
if (!messages) {
try {
const getter = await ASYNC_LOCALES[locale]().then(m => m.default || m)
const getter = await ASYNC_LOCALES[file]().then(m => m.default || m)
messages = typeof getter === 'function' ? await Promise.resolve(getter(context, locale)) : getter
} catch (error) {
// eslint-disable-next-line no-console
Expand Down