Skip to content

Commit e6fa035

Browse files
committed
Add hmr support for ftl files
1 parent 44e8b4e commit e6fa035

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

nuxt-2/plugins/fluent-vue.js

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,38 @@ if (!Object.hasOwnProperty.call(Vue.prototype, 'currentLocale')) {
3535
},
3636

3737
set (locale) {
38-
if (locale === 'en') {
39-
currentLocale = locale
40-
fluent.bundles = [enBundle]
41-
}
42-
43-
if (locale === 'uk') {
44-
currentLocale = locale
45-
fluent.bundles = [ukBundle]
46-
}
47-
48-
// Not sure why this is needed with nuxt 2
49-
for (const component of components.keys()) {
50-
component.$forceUpdate()
51-
}
38+
setLocale(locale)
5239
}
5340
})
5441
}
5542

43+
function setLocale (locale) {
44+
if (locale === 'en') {
45+
currentLocale = locale
46+
fluent.bundles = [enBundle]
47+
}
48+
49+
if (locale === 'uk') {
50+
currentLocale = locale
51+
fluent.bundles = [ukBundle]
52+
}
53+
54+
// Not sure why this is needed with nuxt 2
55+
for (const component of components.keys()) {
56+
component.$forceUpdate()
57+
}
58+
}
59+
5660
export const supportedLocales = [ 'en', 'uk' ]
61+
62+
if (module.hot) {
63+
module.hot.accept('~/locales/en.ftl', function () {
64+
enBundle.addResource(new FluentResource(enMessages), { allowOverrides: true })
65+
setLocale(currentLocale)
66+
});
67+
68+
module.hot.accept('~/locales/uk.ftl', function () {
69+
ukBundle.addResource(new FluentResource(ukMessages), { allowOverrides: true })
70+
setLocale(currentLocale)
71+
});
72+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy