forked from nutomic/joinpeertube
Split translations
This commit is contained in:
parent
e46fa9fba1
commit
06801e7777
5 changed files with 139 additions and 125 deletions
12
Makefile
12
Makefile
|
@ -31,11 +31,15 @@ all:
|
||||||
@echo choose a target from: clean makemessages translations
|
@echo choose a target from: clean makemessages translations
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(TEMPLATE_POT) $(OUTPUT_DIR)/translations.json
|
rm -rf $(TEMPLATE_POT)
|
||||||
|
|
||||||
makemessages: $(TEMPLATE_POT)
|
makemessages: $(TEMPLATE_POT)
|
||||||
|
|
||||||
translations: ./$(OUTPUT_DIR)/translations.json
|
translations: $(LOCALE_FILES)
|
||||||
|
mkdir -p $(OUTPUT_DIR)/translations
|
||||||
|
@for lang in $(LOCALES); do \
|
||||||
|
gettext-compile --output $(OUTPUT_DIR)/translations/$$lang.json $(OUTPUT_DIR)/locale/$$lang/LC_MESSAGES/app.po; \
|
||||||
|
done;
|
||||||
|
|
||||||
# Create a main .pot template, then generate .po files for each available language.
|
# Create a main .pot template, then generate .po files for each available language.
|
||||||
# Thanx to Systematic: https://github.com/Polyconseil/systematic/blob/866d5a/mk/main.mk#L167-L183
|
# Thanx to Systematic: https://github.com/Polyconseil/systematic/blob/866d5a/mk/main.mk#L167-L183
|
||||||
|
@ -58,7 +62,3 @@ $(TEMPLATE_POT): $(GETTEXT_SOURCES)
|
||||||
msgattrib --no-wrap --no-obsolete -o $$PO_FILE $$PO_FILE || break; \
|
msgattrib --no-wrap --no-obsolete -o $$PO_FILE $$PO_FILE || break; \
|
||||||
fi; \
|
fi; \
|
||||||
done;
|
done;
|
||||||
|
|
||||||
$(OUTPUT_DIR)/translations.json: $(LOCALE_FILES)
|
|
||||||
mkdir -p $(OUTPUT_DIR)
|
|
||||||
gettext-compile --output $@ $(LOCALE_FILES)
|
|
||||||
|
|
69
src/main.js
69
src/main.js
|
@ -7,17 +7,13 @@ import VueMeta from 'vue-meta'
|
||||||
import App from './App.vue'
|
import App from './App.vue'
|
||||||
import Home from './views/Home.vue'
|
import Home from './views/Home.vue'
|
||||||
import Help from './views/Help'
|
import Help from './views/Help'
|
||||||
import News from './views/News'
|
|
||||||
import Instances from './views/Instances'
|
import Instances from './views/Instances'
|
||||||
import HallOfFame from './views/Hall-Of-Fame'
|
|
||||||
import FAQ from './views/FAQ'
|
import FAQ from './views/FAQ'
|
||||||
import AllContentSelections from './views/All-Content-Selections'
|
import AllContentSelections from './views/All-Content-Selections'
|
||||||
|
|
||||||
import './scss/main.scss'
|
import './scss/main.scss'
|
||||||
import CommonMixins from './mixins/CommonMixins'
|
import CommonMixins from './mixins/CommonMixins'
|
||||||
|
|
||||||
const translations = require('./translations.json')
|
|
||||||
|
|
||||||
Vue.use(VueRouter)
|
Vue.use(VueRouter)
|
||||||
|
|
||||||
// ############# I18N ##############
|
// ############# I18N ##############
|
||||||
|
@ -32,12 +28,8 @@ const aliasesLanguages = {
|
||||||
}
|
}
|
||||||
const allLocales = Object.keys(availableLanguages).concat(Object.keys(aliasesLanguages))
|
const allLocales = Object.keys(availableLanguages).concat(Object.keys(aliasesLanguages))
|
||||||
|
|
||||||
Vue.use(GetTextPlugin, {
|
const defaultLanguage = 'en_US'
|
||||||
translations,
|
let currentLanguage = defaultLanguage
|
||||||
availableLanguages,
|
|
||||||
defaultLanguage: 'en_US',
|
|
||||||
silent: false
|
|
||||||
})
|
|
||||||
|
|
||||||
const localePath = window.location.pathname
|
const localePath = window.location.pathname
|
||||||
.replace(/^\//, '')
|
.replace(/^\//, '')
|
||||||
|
@ -46,27 +38,47 @@ const localePath = window.location.pathname
|
||||||
const languageFromLocalStorage = localStorage.getItem('language')
|
const languageFromLocalStorage = localStorage.getItem('language')
|
||||||
|
|
||||||
if (allLocales.includes(localePath)) {
|
if (allLocales.includes(localePath)) {
|
||||||
Vue.config.language = aliasesLanguages[localePath] ? aliasesLanguages[localePath] : localePath
|
currentLanguage = aliasesLanguages[localePath] ? aliasesLanguages[localePath] : localePath
|
||||||
localStorage.setItem('language', Vue.config.language)
|
localStorage.setItem('language', currentLanguage)
|
||||||
} else if (languageFromLocalStorage) {
|
} else if (languageFromLocalStorage) {
|
||||||
Vue.config.language = languageFromLocalStorage
|
currentLanguage = languageFromLocalStorage
|
||||||
} else {
|
} else {
|
||||||
const navigatorLanguage = window.navigator.userLanguage || window.navigator.language
|
const navigatorLanguage = window.navigator.userLanguage || window.navigator.language
|
||||||
const snakeCaseLanguage = navigatorLanguage.replace('-', '_')
|
const snakeCaseLanguage = navigatorLanguage.replace('-', '_')
|
||||||
Vue.config.language = aliasesLanguages[snakeCaseLanguage] ? aliasesLanguages[snakeCaseLanguage] : snakeCaseLanguage
|
currentLanguage = aliasesLanguages[snakeCaseLanguage] ? aliasesLanguages[snakeCaseLanguage] : snakeCaseLanguage
|
||||||
}
|
}
|
||||||
|
|
||||||
Vue.filter('translate', value => {
|
Vue.filter('translate', value => {
|
||||||
return value ? Vue.prototype.$gettext(value.toString()) : ''
|
return value ? Vue.prototype.$gettext(value.toString()) : ''
|
||||||
})
|
})
|
||||||
|
|
||||||
// ###########################
|
const p = currentLanguage === defaultLanguage
|
||||||
|
? Promise.resolve({ default: {} })
|
||||||
|
: import('../public/translations/' + currentLanguage + '.json')
|
||||||
|
|
||||||
Vue.use(VueMeta)
|
p.catch(err => {
|
||||||
|
console.error('Cannot load translations.', err)
|
||||||
|
return { default: {} }
|
||||||
|
}).then(module => {
|
||||||
|
Vue.use(GetTextPlugin, {
|
||||||
|
translations: module.default,
|
||||||
|
availableLanguages,
|
||||||
|
defaultLanguage: 'en_US',
|
||||||
|
silent: process.env.NODE_ENV === 'development'
|
||||||
|
})
|
||||||
|
|
||||||
Vue.mixin(CommonMixins)
|
Vue.config.language = currentLanguage
|
||||||
|
|
||||||
const routes = [
|
// ###########################
|
||||||
|
|
||||||
|
Vue.use(VueMeta)
|
||||||
|
|
||||||
|
Vue.mixin(CommonMixins)
|
||||||
|
|
||||||
|
const HallOfFame = () => import('./views/Hall-Of-Fame')
|
||||||
|
const News = () => import('./views/News')
|
||||||
|
|
||||||
|
const routes = [
|
||||||
{
|
{
|
||||||
path: '/',
|
path: '/',
|
||||||
component: Home
|
component: Home
|
||||||
|
@ -95,16 +107,16 @@ const routes = [
|
||||||
path: '/content-selections',
|
path: '/content-selections',
|
||||||
component: AllContentSelections
|
component: AllContentSelections
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
for (const locale of allLocales) {
|
for (const locale of allLocales) {
|
||||||
routes.push({
|
routes.push({
|
||||||
path: '/' + locale,
|
path: '/' + locale,
|
||||||
component: Home
|
component: Home
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const router = new VueRouter({
|
const router = new VueRouter({
|
||||||
mode: 'history',
|
mode: 'history',
|
||||||
base: process.env.BASE_URL,
|
base: process.env.BASE_URL,
|
||||||
routes,
|
routes,
|
||||||
|
@ -115,14 +127,14 @@ const router = new VueRouter({
|
||||||
return { x: 0, y: 0 }
|
return { x: 0, y: 0 }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// Stats Matomo
|
// Stats Matomo
|
||||||
if (!(navigator.doNotTrack === 'yes' ||
|
if (!(navigator.doNotTrack === 'yes' ||
|
||||||
navigator.doNotTrack === '1' ||
|
navigator.doNotTrack === '1' ||
|
||||||
navigator.msDoNotTrack === '1' ||
|
navigator.msDoNotTrack === '1' ||
|
||||||
window.doNotTrack === '1')
|
window.doNotTrack === '1')
|
||||||
) {
|
) {
|
||||||
Vue.use(VueMatomo, {
|
Vue.use(VueMatomo, {
|
||||||
// Configure your matomo server and site
|
// Configure your matomo server and site
|
||||||
host: 'https://stats.framasoft.org/',
|
host: 'https://stats.framasoft.org/',
|
||||||
|
@ -163,9 +175,9 @@ if (!(navigator.doNotTrack === 'yes' ||
|
||||||
|
|
||||||
this.setVisitorCookieTimeout(getOriginalVisitorCookieTimeout())
|
this.setVisitorCookieTimeout(getOriginalVisitorCookieTimeout())
|
||||||
}])
|
}])
|
||||||
}
|
}
|
||||||
|
|
||||||
new Vue({ // eslint-disable-line no-new
|
new Vue({ // eslint-disable-line no-new
|
||||||
el: '#app',
|
el: '#app',
|
||||||
router,
|
router,
|
||||||
mounted () {
|
mounted () {
|
||||||
|
@ -173,4 +185,5 @@ new Vue({ // eslint-disable-line no-new
|
||||||
document.dispatchEvent(new Event('render-event'))
|
document.dispatchEvent(new Event('render-event'))
|
||||||
},
|
},
|
||||||
render: h => h(App)
|
render: h => h(App)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
File diff suppressed because one or more lines are too long
1
src/translations/en_US.json
Normal file
1
src/translations/en_US.json
Normal file
File diff suppressed because one or more lines are too long
1
src/translations/fr_FR.json
Normal file
1
src/translations/fr_FR.json
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue