mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
* wip: client: i18n * remove maxAge from cookies to get same expiration ad localStorage * set cookies expiration to 10 years * moment: load translations in browser, moment: only load necessary data, remove jquery, remove bluebird * ability to change language * fix logout * add some requiresLogin: false to static pages * fix tests
34 lines
1.0 KiB
JavaScript
34 lines
1.0 KiB
JavaScript
// Vue plugin to globally expose a '$t' method that calls common/i18n.t.
|
|
// Can be anywhere inside vue as 'this.$t' or '$t' in templates.
|
|
|
|
import i18n from 'common/script/i18n';
|
|
import moment from 'moment';
|
|
|
|
export default {
|
|
install (Vue, {i18nData}) {
|
|
if (i18nData) {
|
|
// Load i18n strings
|
|
i18n.strings = i18nData.strings;
|
|
|
|
// Load Moment.js locale
|
|
const language = i18nData.language;
|
|
|
|
if (language && i18nData.momentLang && language.momentLangCode) {
|
|
// Make moment available under `window` so that the locale can be set
|
|
window.moment = moment;
|
|
|
|
// Execute the script and set the locale
|
|
const head = document.getElementsByTagName('head')[0];
|
|
const script = document.createElement('script');
|
|
script.type = 'text/javascript';
|
|
script.text = i18nData.momentLang;
|
|
head.appendChild(script);
|
|
moment.locale(language.momentLangCode);
|
|
}
|
|
}
|
|
|
|
Vue.prototype.$t = function translateString () {
|
|
return i18n.t.apply(null, arguments);
|
|
};
|
|
},
|
|
}; |