Commit 3d5a912d4f26780685c60d2ccc930cd6dd9567cc
i18n + more translations
Joran authored on 4/27/2017, 11:07:03 PMMarcos Gutierrez committed on 9/29/2017, 12:59:36 PM
Parent: 771e58efb5920f3b771f41b4c98a7905a56975ee
Files changed
index.js | changed |
lib/window.js | changed |
lib/i18n.js | added |
main-window.js | changed |
modules/app/html/search.js | changed |
modules/feed/html/rollup.js | changed |
modules/page/html/render/public.js | changed |
package.json | changed |
server-process.js | changed |
locales/en.json | added |
locales/ki.json | added |
index.js | ||
---|---|---|
@@ -2,8 +2,10 @@ | ||
2 | 2 | console.log(err) |
3 | 3 | process.exit() |
4 | 4 | }) |
5 | 5 | |
6 | +var i18n = require('./lib/i18n').i18n | |
7 | + | |
6 | 8 | var electron = require('electron') |
7 | 9 | var openWindow = require('./lib/window') |
8 | 10 | |
9 | 11 | var Path = require('path') |
@@ -18,8 +20,9 @@ | ||
18 | 20 | } |
19 | 21 | var ssbConfig = null |
20 | 22 | var quitting = false |
21 | 23 | |
24 | + | |
22 | 25 | electron.app.on('ready', () => { |
23 | 26 | setupContext('ssb', { |
24 | 27 | server: !(process.argv.includes('-g') || process.argv.includes('--use-global-ssb')) |
25 | 28 | }, () => { |
@@ -79,9 +82,9 @@ | ||
79 | 82 | width: windowState.width, |
80 | 83 | height: windowState.height, |
81 | 84 | titleBarStyle: 'hidden-inset', |
82 | 85 | autoHideMenuBar: true, |
83 | - title: 'Patchwork', | |
86 | + title: i18n.__("Patchwork"), | |
84 | 87 | show: true, |
85 | 88 | backgroundColor: '#EEE', |
86 | 89 | webPreferences: { |
87 | 90 | experimentalFeatures: true |
lib/window.js | ||
---|---|---|
@@ -18,9 +18,9 @@ | ||
18 | 18 | electron.webFrame.setZoomLevelLimits(1, 1) |
19 | 19 | |
20 | 20 | var config = ${JSON.stringify(config)} |
21 | 21 | var data = ${JSON.stringify(opts.data)} |
22 | - var title = ${JSON.stringify(opts.title || 'Patchwork')} | |
22 | + var title = ${JSON.stringify(opts.title || i18n.__("Patchwork"))} | |
23 | 23 | |
24 | 24 | document.documentElement.querySelector('head').appendChild( |
25 | 25 | h('title', title) |
26 | 26 | ) |
lib/i18n.js | ||
---|---|---|
@@ -1,0 +1,12 @@ | ||
1 | +// Multi Language support | |
2 | +var appRoot = require('app-root-path'); | |
3 | + | |
4 | +var i18n = require("i18n") | |
5 | +i18n.configure({ | |
6 | + locales:['en','ki'], | |
7 | + directory: appRoot + '/locales' | |
8 | +}); | |
9 | + | |
10 | +i18n.setLocale('ki') | |
11 | + | |
12 | +exports.i18n = i18n; |
main-window.js | ||
---|---|---|
@@ -11,9 +11,11 @@ | ||
11 | 11 | var LatestUpdate = require('./lib/latest-update') |
12 | 12 | var ref = require('ssb-ref') |
13 | 13 | var setupContextMenuAndSpellCheck = require('./lib/context-menu-and-spellcheck') |
14 | 14 | var watch = require('mutant/watch') |
15 | +var i18n = require('./lib/i18n').i18n | |
15 | 16 | |
17 | + | |
16 | 18 | module.exports = function (config) { |
17 | 19 | var sockets = combine( |
18 | 20 | overrideConfig(config), |
19 | 21 | addCommand('app.navigate', setView), |
@@ -90,10 +92,10 @@ | ||
90 | 92 | classList: [ when(views.canGoForward, '-active') ] |
91 | 93 | }) |
92 | 94 | ]), |
93 | 95 | h('span.nav', [ |
94 | - tab('Public', '/public'), | |
95 | - tab('Private', '/private'), | |
96 | + tab(i18n.__("Public"), '/public'), | |
97 | + tab(i18n.__("Private"), '/private'), | |
96 | 98 | dropTab('More', [ |
97 | 99 | getSubscribedChannelMenu, |
98 | 100 | ['Gatherings', '/gatherings'], |
99 | 101 | ['Extended Network', '/all'], |
@@ -101,15 +103,15 @@ | ||
101 | 103 | ['Settings', '/settings'] |
102 | 104 | ]) |
103 | 105 | ]), |
104 | 106 | h('span.appTitle', [ |
105 | - h('span.title', 'Patchwork'), | |
107 | + h('span.title', i18n.__("Patchwork")), | |
106 | 108 | api.app.html.progressNotifier() |
107 | 109 | ]), |
108 | 110 | h('span', [ api.app.html.search(api.app.navigate) ]), |
109 | 111 | h('span.nav', [ |
110 | - tab('Profile', id), | |
111 | - tab('Mentions', '/mentions') | |
112 | + tab(i18n.__('Profile'), id), | |
113 | + tab(i18n.__('Mentions'), '/mentions') | |
112 | 114 | ]) |
113 | 115 | ]), |
114 | 116 | when(latestUpdate, |
115 | 117 | h('div.info', [ |
modules/app/html/search.js | ||
---|---|---|
@@ -1,8 +1,12 @@ | ||
1 | 1 | var h = require('mutant/h') |
2 | 2 | var nest = require('depnest') |
3 | 3 | var addSuggest = require('suggest-box') |
4 | 4 | |
5 | +var appRoot = require('app-root-path'); | |
6 | +var i18n = require(appRoot + '/lib/i18n').i18n | |
7 | + | |
8 | + | |
5 | 9 | exports.needs = nest({ |
6 | 10 | 'profile.async.suggest': 'first', |
7 | 11 | 'channel.async.suggest': 'first' |
8 | 12 | }) |
@@ -16,9 +20,9 @@ | ||
16 | 20 | var getProfileSuggestions = api.profile.async.suggest() |
17 | 21 | var getChannelSuggestions = api.channel.async.suggest() |
18 | 22 | var searchBox = h('input.search', { |
19 | 23 | type: 'search', |
20 | - placeholder: 'word, @key, #channel', | |
24 | + placeholder: i18n.__('word, @key, #channel'), | |
21 | 25 | 'ev-suggestselect': (ev) => { |
22 | 26 | setView(ev.detail.id) |
23 | 27 | searchBox.value = ev.detail.id |
24 | 28 | }, |
modules/feed/html/rollup.js | ||
---|---|---|
@@ -17,8 +17,12 @@ | ||
17 | 17 | |
18 | 18 | // bump even for first message |
19 | 19 | var rootBumpTypes = ['mention', 'channel-mention'] |
20 | 20 | |
21 | +var appRoot = require('app-root-path'); | |
22 | +var i18n = require(appRoot + '/lib/i18n').i18n | |
23 | + | |
24 | + | |
21 | 25 | exports.needs = nest({ |
22 | 26 | 'about.obs.name': 'first', |
23 | 27 | 'app.sync.externalHandler': 'first', |
24 | 28 | 'message.html.render': 'first', |
@@ -46,9 +50,9 @@ | ||
46 | 50 | var updates = Value(0) |
47 | 51 | var yourId = api.keys.sync.id() |
48 | 52 | var throttledUpdates = throttle(updates, 200) |
49 | 53 | var updateLoader = h('a Notifier -loader', { href: '#', 'ev-click': refresh }, [ |
50 | - 'Show ', h('strong', [throttledUpdates]), ' ', plural(throttledUpdates, 'update', 'updates') | |
54 | + 'Show ', h('strong', [throttledUpdates]), ' ', plural(throttledUpdates, i18n.__('update'), i18n.__('updates')) | |
51 | 55 | ]) |
52 | 56 | |
53 | 57 | var abortLastFeed = null |
54 | 58 | var content = Value() |
@@ -253,27 +257,27 @@ | ||
253 | 257 | if (ids.length > 4) { |
254 | 258 | return [ |
255 | 259 | fn(featuredIds[0]), ', ', |
256 | 260 | fn(featuredIds[1]), ', ', |
257 | - fn(featuredIds[2]), ' and ', | |
258 | - ids.length - 3, ' others' | |
261 | + fn(featuredIds[2]), i18n.__(' and '), | |
262 | + ids.length - 3, i18n.__(' others') | |
259 | 263 | ] |
260 | 264 | } else if (ids.length === 4) { |
261 | 265 | return [ |
262 | 266 | fn(featuredIds[0]), ', ', |
263 | 267 | fn(featuredIds[1]), ', ', |
264 | - fn(featuredIds[2]), ' and ', | |
268 | + fn(featuredIds[2]), i18n.__(' and '), | |
265 | 269 | fn(featuredIds[3]) |
266 | 270 | ] |
267 | 271 | } else if (ids.length === 3) { |
268 | 272 | return [ |
269 | 273 | fn(featuredIds[0]), ', ', |
270 | - fn(featuredIds[1]), ' and ', | |
274 | + fn(featuredIds[1]), i18n.__(' and '), | |
271 | 275 | fn(featuredIds[2]) |
272 | 276 | ] |
273 | 277 | } else if (ids.length === 2) { |
274 | 278 | return [ |
275 | - fn(featuredIds[0]), ' and ', | |
279 | + fn(featuredIds[0]), i18n.__(' and '), | |
276 | 280 | fn(featuredIds[1]) |
277 | 281 | ] |
278 | 282 | } else { |
279 | 283 | return fn(featuredIds[0]) |
modules/page/html/render/public.js | ||
---|---|---|
@@ -3,8 +3,12 @@ | ||
3 | 3 | var pull = require('pull-stream') |
4 | 4 | var normalizeChannel = require('../../../../lib/normalize-channel') |
5 | 5 | var { h, send, when, computed, map } = require('mutant') |
6 | 6 | |
7 | +var appRoot = require('app-root-path'); | |
8 | +var i18n = require(appRoot + '/lib/i18n').i18n | |
9 | + | |
10 | + | |
7 | 11 | exports.needs = nest({ |
8 | 12 | sbot: { |
9 | 13 | obs: { |
10 | 14 | connectedPeers: 'first', |
@@ -52,9 +56,9 @@ | ||
52 | 56 | var localPeers = api.sbot.obs.localPeers() |
53 | 57 | var connectedPubs = computed([connectedPeers, localPeers], (c, l) => c.filter(x => !l.includes(x))) |
54 | 58 | |
55 | 59 | var prepend = [ |
56 | - api.message.html.compose({ meta: { type: 'post' }, placeholder: 'Write a public message' }) | |
60 | + api.message.html.compose({ meta: { type: 'post' }, placeholder: i18n.__('Write a public message') }) | |
57 | 61 | ] |
58 | 62 | |
59 | 63 | var getStream = (opts) => { |
60 | 64 | if (opts.lt != null && !opts.lt.marker) { |
@@ -111,11 +115,11 @@ | ||
111 | 115 | }) |
112 | 116 | return [ |
113 | 117 | h('button -pub -full', { |
114 | 118 | 'ev-click': api.invite.sheet |
115 | - }, '+ Join Pub'), | |
116 | - when(loading, [ h('Loading') ], [ | |
117 | - when(computed(channels, x => x.length), h('h2', 'Active Channels')), | |
119 | + }, i18n.__('+ Join Pub')), | |
120 | + when(loading, [ h(i18n.__("Loading")) ], [ | |
121 | + when(computed(channels, x => x.length), h('h2', i18n.__("Active Channels"))), | |
118 | 122 | h('div', { |
119 | 123 | classList: 'ChannelList', |
120 | 124 | hidden: loading |
121 | 125 | }, [ |
@@ -130,23 +134,23 @@ | ||
130 | 134 | h('span.name', '#' + channel), |
131 | 135 | when(subscribed, |
132 | 136 | h('a.-unsubscribe', { |
133 | 137 | 'ev-click': send(unsubscribe, channel) |
134 | - }, 'Unsubscribe'), | |
138 | + }, i18n.__('Unsubscribe')), | |
135 | 139 | h('a.-subscribe', { |
136 | 140 | 'ev-click': send(subscribe, channel) |
137 | - }, 'Subscribe') | |
141 | + }, i18n.__('Subscribe')) | |
138 | 142 | ) |
139 | 143 | ]) |
140 | 144 | }, {maxTime: 5}), |
141 | - h('a.channel -more', {href: '/channels'}, 'More Channels...') | |
145 | + h('a.channel -more', {href: '/channels'}, i18n.__('More Channels...')) | |
142 | 146 | ]) |
143 | 147 | ]), |
144 | 148 | |
145 | - PeerList(localPeers, 'Local'), | |
146 | - PeerList(connectedPubs, 'Connected Pubs'), | |
149 | + PeerList(localPeers, i18n.__('Local')), | |
150 | + PeerList(connectedPubs, i18n.__('Connected Pubs')), | |
147 | 151 | |
148 | - when(computed(whoToFollow, x => x.length), h('h2', 'Who to follow')), | |
152 | + when(computed(whoToFollow, x => x.length), h('h2', i18n.__('Who to follow'))), | |
149 | 153 | when(following.sync, |
150 | 154 | h('div', { |
151 | 155 | classList: 'ProfileList' |
152 | 156 | }, [ |
package.json | ||
---|---|---|
@@ -1,7 +1,7 @@ | ||
1 | 1 | { |
2 | 2 | "name": "ssb-patchwork", |
3 | - "productName": "Patchwork", | |
3 | + "productName": "patchwork", | |
4 | 4 | "repository": "git@github.com:ssbc/patchwork.git", |
5 | 5 | "version": "3.6.6", |
6 | 6 | "description": "A decentralized messaging and sharing app built on top of Secure Scuttlebutt (SSB).", |
7 | 7 | "main": "index.js", |
@@ -13,8 +13,9 @@ | ||
13 | 13 | }, |
14 | 14 | "author": "Secure Scuttlebutt Consortium", |
15 | 15 | "license": "AGPL-3.0", |
16 | 16 | "dependencies": { |
17 | + "app-root-path": "^2.0.1", | |
17 | 18 | "bulk-require": "^1.0.0", |
18 | 19 | "compare-version": "^0.1.2", |
19 | 20 | "cross-script": "^1.0.1", |
20 | 21 | "deep-equal": "^1.0.1", |
@@ -26,8 +27,9 @@ | ||
26 | 27 | "fix-path": "^2.1.0", |
27 | 28 | "flatpickr": "^3.0.5-1", |
28 | 29 | "flumeview-level": "^2.0.3", |
29 | 30 | "hashlru": "^2.2.0", |
31 | + "i18n": "^0.8.3", | |
30 | 32 | "insert-css": "~2.0.0", |
31 | 33 | "level": "~1.7.0", |
32 | 34 | "lrucache": "^1.0.2", |
33 | 35 | "micro-css": "^2.0.1", |
server-process.js | ||
---|---|---|
@@ -1,4 +1,6 @@ | ||
1 | +global.i18n = require('./lib/i18n').i18n | |
2 | + | |
1 | 3 | var serveBlobs = require('./lib/serve-blobs') |
2 | 4 | var fs = require('fs') |
3 | 5 | var Path = require('path') |
4 | 6 | var electron = require('electron') |
locales/en.json | ||
---|---|---|
@@ -1,0 +1,13 @@ | ||
1 | +{ | |
2 | + "Patchwork": "Patchwork", | |
3 | + "Public": "Public", | |
4 | + "Private": "Private", | |
5 | + "Write a public message": "Write a public message", | |
6 | + "Active Channels": "Active Channels", | |
7 | + "Loading": "Loading", | |
8 | + "Local": "Local", | |
9 | + "Connected Pubs": "Connected Pubs", | |
10 | + "Who to follow": "Who to follow", | |
11 | + "Unsubscribe": "Unsubscribe", | |
12 | + "Subscribe": "Subscribe" | |
13 | +} |
locales/ki.json | ||
---|---|---|
@@ -1,0 +1,29 @@ | ||
1 | +{ | |
2 | + "Write a public message": "پبلک پیغام لکھنے", | |
3 | + "Active Channels": "فعال", | |
4 | + "Loading": "لوڈ ہو رہا ہے", | |
5 | + "Local": "مقامی", | |
6 | + "Connected Pubs": "مربوط عوامی مقامات", | |
7 | + "Who to follow": "جو پیروی کرنے کے لئے", | |
8 | + "Public": "عوام", | |
9 | + "Private": "نجی", | |
10 | + "Patchwork": "जन्द । नक्तकः", | |
11 | + "Unsubscribe": "رکنیت ختم", | |
12 | + "Subscribe": "سبسکرائب", | |
13 | + "+ Join Pub": "+ عوامی جگہ شمولیت", | |
14 | + "Profile": "تم", | |
15 | + "Mentions": "تذکرے", | |
16 | + "Show ": "شو ", | |
17 | + "update": "اپ ڈیٹ", | |
18 | + "updates": "اپ ڈیٹ", | |
19 | + " liked this message": " اس پیغام کو پسند کیا", | |
20 | + "View full thread": "مکمل دھاگے کو دیکھیں", | |
21 | + " replied": " جواب", | |
22 | + " subscribed to ": " سبسکرائب ", | |
23 | + " replied to ": " کا جواب دیا ", | |
24 | + " followed ": " کی پیروی کی ", | |
25 | + " and ": " اور ", | |
26 | + " others": " دوسروں", | |
27 | + " liked ": " پسند کیا ", | |
28 | + "word, @key, #channel": "word, @key, #channel" | |
29 | +} |
Built with git-ssb-web