git ssb

10+

Matt McKegg / patchwork



Commit e5dd29c7a0d68080004e28769bbfed143db66881

Wrap i18n into depject

Marcos Gutierrez committed on 9/29/2017, 2:36:48 PM
Parent: 77e7fa628b43035fa4c24ea1a9eb35529874721d

Files changed

lib/i18n.jsdeleted
plugs/intl/sync/i18n.jsadded
lib/i18n.jsView
@@ -1,12 +1,0 @@
1-// Multi Language support
2-var appRoot = require('app-root-path');
3-
4-var i18n = require("i18n")
5-i18n.configure({
6- locales:['en','ki','es'],
7- directory: appRoot + '/locales'
8-});
9-
10-i18n.setLocale('en')
11-
12-exports.i18n = i18n;
plugs/intl/sync/i18n.jsView
@@ -1,0 +1,69 @@
1+const nest = require('depnest')
2+var { watch } = require('mutant')
3+var appRoot = require('app-root-path');
4+var i18nL = require("i18n")
5+
6+exports.gives = nest('intl.sync', [
7+ 'locale',
8+ 'locales',
9+ 'i18n',
10+])
11+
12+exports.needs = nest({
13+ 'intl.sync.locale':'first',
14+ 'intl.sync.locales':'reduce',
15+ 'settings.obs.get': 'first',
16+ 'settings.sync.set': 'first'
17+})
18+
19+exports.create = (api) => {
20+ let _locale
21+
22+ const {
23+ locale: getLocale,
24+ locales: getLocales,
25+ i18n: getI18n,
26+ } = api.intl.sync
27+
28+ return nest('intl.sync', {
29+ locale,
30+ locales,
31+ i18n
32+ })
33+
34+ //Get locale value in setting
35+ function locale () {
36+ return api.settings.obs.get('patchwork.lang')
37+ }
38+
39+ //Get all locales loaded in i18nL
40+ function locales (sofar = {}) {
41+ return i18nL.getLocales()
42+ }
43+
44+ //Get translation
45+ function i18n (value) {
46+ _init()
47+ return i18nL.__(value)
48+ }
49+
50+ //Init an subscribe to settings changes.
51+ function _init() {
52+ if (_locale) return
53+ //TODO: Depject this!
54+ i18nL.configure({
55+ locales:['en','ki','es'],
56+ directory: appRoot + '/locales'
57+ });
58+
59+ watch(api.settings.obs.get('patchwork.lang'), currentLocale => {
60+ i18nL.setLocale(currentLocale)
61+ })
62+ }
63+
64+}
65+
66+//For now get only global languages
67+function getSubLocal(loc) {
68+ return loc.split('-')[0]
69+}

Built with git-ssb-web