Permalink
Browse files

Change global i18n to a depject approach

  • Loading branch information...
gmarcos87 committed Sep 29, 2017
1 parent d245481 commit 77e7fa628b43035fa4c24ea1a9eb35529874721d
View
@@ -3,8 +3,6 @@ process.on('uncaughtException', function (err) {
process.exit()
})
var i18n = require('./lib/i18n').i18n
var electron = require('electron')
var openWindow = require('./lib/window')
@@ -83,7 +81,7 @@ function openMainWindow () {
height: windowState.height,
titleBarStyle: 'hidden-inset',
autoHideMenuBar: true,
title: i18n.__("Patchwork"),
title: "Patchwork",
show: true,
backgroundColor: '#EEE',
webPreferences: {
View
@@ -19,7 +19,7 @@ module.exports = function Window (config, path, opts) {
var config = ${JSON.stringify(config)}
var data = ${JSON.stringify(opts.data)}
var title = ${JSON.stringify(opts.title || i18n.__("Patchwork"))}
var title = ${JSON.stringify(opts.title || "Patchwork" )}
document.documentElement.querySelector('head').appendChild(
h('title', title)
View
@@ -12,7 +12,6 @@ var LatestUpdate = require('./lib/latest-update')
var ref = require('ssb-ref')
var setupContextMenuAndSpellCheck = require('./lib/context-menu-and-spellcheck')
var watch = require('mutant/watch')
var i18n = require('./lib/i18n').i18n
module.exports = function (config) {
@@ -42,14 +41,17 @@ module.exports = function (config) {
'app.navigate': 'first',
'channel.obs.subscribed': 'first',
'settings.obs.get': 'first',
'intl.sync.i18n': 'first',
}))
setupContextMenuAndSpellCheck(api.config.sync.load())
const i18n = api.intl.sync.i18n
var id = api.keys.sync.id()
var latestUpdate = LatestUpdate()
var subscribedChannels = api.channel.obs.subscribed(id)
// prompt to setup profile on first use
onceTrue(api.sbot.obs.connection, (sbot) => {
sbot.latestSequence(sbot.id, (_, key) => {
@@ -93,30 +95,30 @@ module.exports = function (config) {
})
]),
h('span.nav', [
tab(i18n.__("Public"), '/public'),
tab(i18n.__("Private"), '/private'),
dropTab(i18n.__('More'), [
tab(i18n("Public"), '/public'),
tab(i18n("Private"), '/private'),
dropTab(i18n('More'), [
getSubscribedChannelMenu,
[i18n.__('Gatherings'), '/gatherings'],
[i18n.__('Extended Network'), '/all'],
[i18n('Gatherings'), '/gatherings'],
[i18n('Extended Network'), '/all'],
{separator: true},
[i18n.__('Settings'), '/settings']
[i18n('Settings'), '/settings']
])
]),
h('span.appTitle', [
h('span.title', i18n.__("Patchwork")),
h('span.title', i18n("Patchwork")),
api.app.html.progressNotifier()
]),
h('span', [ api.app.html.search(api.app.navigate) ]),
h('span.nav', [
tab(i18n.__('Profile'), id),
tab(i18n.__('Mentions'), '/mentions')
tab(i18n('Profile'), id),
tab(i18n('Mentions'), '/mentions')
])
]),
when(latestUpdate,
h('div.info', [
h('a.message -update', { href: 'https://github.com/ssbc/patchwork/releases' }, [
h('strong', ['Patchwork ', latestUpdate, i18n.__(' has been released.')]), i18n.__(' Click here to download and view more info!'),
h('strong', ['Patchwork ', latestUpdate, i18n(' has been released.')]), i18n(' Click here to download and view more info!'),
h('a.ignore', {'ev-click': latestUpdate.ignore}, 'X')
])
])
@@ -152,9 +154,9 @@ module.exports = function (config) {
if (channels.length) {
return {
label: i18n.__('Channels'),
label: i18n('Channels'),
submenu: [
{ label: i18n.__('Browse All'),
{ label: i18n('Browse All'),
click () {
setView('/channels')
}
@@ -171,7 +173,7 @@ module.exports = function (config) {
}
} else {
return {
label: i18n.__('Browse Channels'),
label: i18n('Browse Channels'),
click () {
setView('/channels')
}
@@ -1,8 +1,7 @@
var {computed, when, h, Value} = require('mutant')
var nest = require('depnest')
var sustained = require('../../../lib/sustained')
var appRoot = require('app-root-path');
var i18n = require(appRoot + '/lib/i18n').i18n
const pull = require('pull-stream')
exports.gives = nest('app.html.progressNotifier')
@@ -13,10 +12,12 @@ exports.needs = nest({
indexes: 'first',
replicate: 'first',
migration: 'first'
}
},
'intl.sync.i18n':'first'
})
exports.create = function (api) {
const i18n = api.intl.sync.i18n
return nest('app.html.progressNotifier', function (id) {
var replicateProgress = api.progress.obs.replicate()
var indexes = api.progress.obs.indexes()
@@ -48,12 +49,12 @@ exports.create = function (api) {
h('div.status', [
when(displaying, h('Loading -small', [
when(pendingMigration,
[h('span.info', i18n.__('Upgrading database')), h('progress', { style: {'margin-left': '10px'}, min: 0, max: 1, value: migrationProgress })],
[h('span.info', i18n('Upgrading database')), h('progress', { style: {'margin-left': '10px'}, min: 0, max: 1, value: migrationProgress })],
when(computed(replicateProgress.incompleteFeeds, (v) => v > 5),
[h('span.info', i18n.__('Downloading new messages')), h('progress', { style: {'margin-left': '10px'}, min: 0, max: 1, value: downloadProgress })],
[h('span.info', i18n('Downloading new messages')), h('progress', { style: {'margin-left': '10px'}, min: 0, max: 1, value: downloadProgress })],
when(pending, [
[h('span.info', i18n.__('Indexing database')), h('progress', { style: {'margin-left': '10px'}, min: 0, max: 1, value: indexProgress })]
], i18n.__('Scuttling...'))
[h('span.info', i18n('Indexing database')), h('progress', { style: {'margin-left': '10px'}, min: 0, max: 1, value: indexProgress })]
], i18n('Scuttling...'))
)
)
]))
@@ -3,25 +3,25 @@ var nest = require('depnest')
var addSuggest = require('suggest-box')
var appRoot = require('app-root-path');
var i18n = require(appRoot + '/lib/i18n').i18n
exports.needs = nest({
'profile.async.suggest': 'first',
'channel.async.suggest': 'first'
'channel.async.suggest': 'first',
'intl.sync.i18n': 'first'
})
exports.gives = nest('app.html.search')
var pages = ['/public', '/private', '/mentions', '/all', '/gatherings']
exports.create = function (api) {
const i18n = api.intl.sync.i18n
return nest('app.html.search', function (setView) {
var getProfileSuggestions = api.profile.async.suggest()
var getChannelSuggestions = api.channel.async.suggest()
var searchBox = h('input.search', {
type: 'search',
placeholder: i18n.__('word, @key, #channel'),
placeholder: i18n('word, @key, #channel'),
'ev-suggestselect': (ev) => {
setView(ev.detail.id)
searchBox.value = ev.detail.id
@@ -7,15 +7,12 @@ var nextStepper = require('../../../lib/next-stepper')
var extend = require('xtend')
var paramap = require('pull-paramap')
var appRoot = require('app-root-path');
var i18n = require(appRoot + '/lib/i18n').i18n
var bumpMessages = {
'vote': i18n.__('liked this message'),
'post': i18n.__('replied to this message'),
'about': i18n.__('added changes'),
'mention': i18n.__('mentioned you'),
'channel-mention': i18n.__('mentioned this channel')
'vote': 'liked this message',
'post': 'replied to this message',
'about': 'added changes',
'mention': 'mentioned you',
'channel-mention': 'mentioned this channel'
}
// bump even for first message
@@ -31,14 +28,16 @@ exports.needs = nest({
'message.sync.root': 'first',
'feed.pull.rollup': 'first',
'sbot.async.get': 'first',
'keys.sync.id': 'first'
'keys.sync.id': 'first',
'intl.sync.i18n': 'first',
})
exports.gives = nest({
'feed.html.rollup': true
})
exports.create = function (api) {
const i18n = api.intl.sync.i18n
return nest('feed.html.rollup', function (getStream, {
prepend,
rootFilter = returnTrue,
@@ -51,7 +50,7 @@ exports.create = function (api) {
var yourId = api.keys.sync.id()
var throttledUpdates = throttle(updates, 200)
var updateLoader = h('a Notifier -loader', { href: '#', 'ev-click': refresh }, [
'Show ', h('strong', [throttledUpdates]), ' ', plural(throttledUpdates, i18n.__('update'), i18n.__('updates'))
'Show ', h('strong', [throttledUpdates]), ' ', plural(throttledUpdates, i18n('update'), i18n('updates'))
])
var abortLastFeed = null
@@ -195,9 +194,9 @@ exports.create = function (api) {
? getLikeAuthors(groupedBumps[lastBumpType])
: getAuthors(groupedBumps[lastBumpType])
var description = bumpMessages[lastBumpType] || 'added changes'
var description = i18n(bumpMessages[lastBumpType] || 'added changes')
meta = h('div.meta', { title: names(bumps) }, [
many(bumps, api.profile.html.person), ' ', description
many(bumps, api.profile.html.person, i18n), ' ', description
])
}
@@ -210,7 +209,7 @@ exports.create = function (api) {
renderedMessage,
when(replyElements.length, [
when(replies.length > replyElements.length || partial,
h('a.full', {href: item.key}, [i18n.__('View full thread') +' (', replies.length, ')'])
h('a.full', {href: item.key}, [i18n('View full thread') +' (', replies.length, ')'])
),
h('div.replies', replyElements)
])
@@ -249,7 +248,7 @@ function plural (value, single, many) {
})
}
function many (ids, fn) {
function many (ids, fn, intl) {
ids = Array.from(ids)
var featuredIds = ids.slice(0, 4)
@@ -258,25 +257,25 @@ function many (ids, fn) {
return [
fn(featuredIds[0]), ', ',
fn(featuredIds[1]), ', ',
fn(featuredIds[2]), i18n.__(' and '),
ids.length - 3, i18n.__(' others')
fn(featuredIds[2]), intl(' and '),
ids.length - 3, intl(' others'),
]
} else if (ids.length === 4) {
return [
fn(featuredIds[0]), ', ',
fn(featuredIds[1]), ', ',
fn(featuredIds[2]), i18n.__(' and '),
fn(featuredIds[2]), intl(' and '),
fn(featuredIds[3])
]
} else if (ids.length === 3) {
return [
fn(featuredIds[0]), ', ',
fn(featuredIds[1]), i18n.__(' and '),
fn(featuredIds[1]), intl(' and '),
fn(featuredIds[2])
]
} else if (ids.length === 2) {
return [
fn(featuredIds[0]), i18n.__(' and '),
fn(featuredIds[0]), intl(' and '),
fn(featuredIds[1])
]
} else {
@@ -2,8 +2,6 @@ var nest = require('depnest')
var extend = require('xtend')
var Pickr = require('flatpickr')
var spacetime = require('spacetime')
var appRoot = require('app-root-path');
var i18n = require(appRoot + '/lib/i18n').i18n
var {Value, h, computed, when} = require('mutant')
@@ -15,10 +13,12 @@ exports.needs = nest({
'sbot.async.publish': 'first',
'about.obs.latestValue': 'first',
'blob.html.input': 'first',
'blob.sync.url': 'first'
'blob.sync.url': 'first',
'intl.sync.i18n': 'first',
})
exports.create = function (api) {
const i18n = api.intl.sync.i18n
return nest('gathering.sheet.edit', function (id) {
api.sheet.display(close => {
var current = id ? {
@@ -55,30 +55,30 @@ exports.create = function (api) {
style: {
'font-weight': 'normal'
}
}, [id ? i18n.__('Edit') : i18n.__('Create'), i18n.__(' Gathering')]),
}, [id ? i18n('Edit') : i18n('Create'), i18n(' Gathering')]),
h('GatheringEditor', [
h('input.title', {
placeholder: i18n.__('Choose a title'),
placeholder: i18n('Choose a title'),
hooks: [ValueHook(chosen.title), FocusHook()]
}),
h('input.date', {
placeholder: i18n.__('Choose date and time'),
placeholder: i18n('Choose date and time'),
hooks: [
PickrHook(chosen.startDateTime)
]
}),
h('ImageInput .banner', {
style: { 'background-image': computed(imageUrl, x => `url(${x})`) }
}, [
h('span', ['🖼 ', i18n.__('Choose Banner Image...')]),
h('span', ['🖼 ', i18n('Choose Banner Image...')]),
api.blob.html.input(file => {
chosen.image.set(file)
}, {
accept: 'image/*'
})
]),
h('textarea.description', {
placeholder: i18n.__('Describe the gathering (if you want)'),
placeholder: i18n('Describe the gathering (if you want)'),
hooks: [ValueHook(chosen.description)]
})
])
@@ -87,10 +87,10 @@ exports.create = function (api) {
h('button -save', {
'ev-click': save,
'disabled': publishing
}, when(publishing, i18n.__('Publishing...'), i18n.__('Publish'))),
}, when(publishing, i18n('Publishing...'), i18n('Publish'))),
h('button -cancel', {
'ev-click': close
}, i18n.__('Cancel'))
}, i18n('Cancel'))
]
}
@@ -113,7 +113,7 @@ exports.create = function (api) {
if (!compareImage(chosen.image(), current.image())) update.image = chosen.image()
if (!compareTime(chosen.startDateTime(), current.startDateTime())) update.startDateTime = chosen.startDateTime()
if (chosen.title() !== current.title()) update.title = chosen.title() || i18n.__('Untitled Gathering')
if (chosen.title() !== current.title()) update.title = chosen.title() || i18n('Untitled Gathering')
if (chosen.description() !== current.description()) update.description = chosen.description()
if (Object.keys(update).length) {
@@ -128,9 +128,9 @@ exports.create = function (api) {
publishing.set(false)
showDialog({
type: 'error',
title: i18n.__('Error'),
title: i18n('Error'),
buttons: ['OK'],
message: i18n.__('An error occurred while attempting to publish gathering.'),
message: i18n('An error occurred while attempting to publish gathering.'),
detail: err.message
})
} else {
Oops, something went wrong.

0 comments on commit 77e7fa6

Please sign in to comment.