git ssb

10+

Matt McKegg / patchwork



Commit f98587b805da63c46cc6810f870c08e333ff5f4d

change language picker into dropdown with full language names

Matt McKegg committed on 9/30/2017, 3:29:42 AM
Parent: 1aabebc53a78d5dfda5dbeacba5db26ca946d64e

Files changed

locales/en.jsonchanged
locales/es.jsonchanged
locales/ki.jsonchanged
modules/page/html/render/settings.jschanged
plugs/intl/sync/i18n.jschanged
locales/en.jsonView
@@ -1,5 +1,8 @@
11 {
2+ "$name": "English",
3+ "es": "Spanish",
4+ "ki": "Kashmiri",
25 "Patchwork": "Patchwork",
36 "Public": "Public",
47 "Private": "Private",
58 "Write a public message": "Write a public message",
@@ -108,29 +111,30 @@
108111 "Theme": "Theme",
109112 "Language": "Language",
110113 "Filters": "Filters",
111114 " Hide following messages": " Hide following messages",
112- "Cannot display message" : "Cannot display message",
113- "Search Results:" : "Search Results:",
114- "Search completed." : "Search completed.",
115- "result found" : "result found",
116- "results found" : "results found",
117- " forked this discussion:" : " forked this discussion:",
118- "Your Profile" : "Your Profile",
119- "Choose Profile Image..." : "Choose Profile Image...",
120- "Choose a name" : "Choose a name",
121- "Describe yourself (if you want)" : "Describe yourself (if you want)",
122- "What whould you like to call " : "What whould you like to call ",
123- "Confirm" : "Confirm",
124- "self assigned a display image" : "self assigned a display image",
125- "Like" : "Like",
126- "Reply" : "Reply",
127- "unfollowed " : "unfollowed ",
128- "Untitled Gathering" : "Untitled Gathering",
129- "Error" : "Error",
130- "An error occurred while attempting to publish gathering." : "An error occurred while attempting to publish gathering.",
131- "An error occurred while attempting to redeem invite." : "An error occurred while attempting to redeem invite.",
132- "OK" : "OK",
133- "Close" : "Close",
134- "New Message" : "New Message",
135- "unsubscribed from " : "unsubscribed from "
115+ "Cannot display message": "Cannot display message",
116+ "Search Results:": "Search Results:",
117+ "Search completed.": "Search completed.",
118+ "result found": "result found",
119+ "results found": "results found",
120+ " forked this discussion:": " forked this discussion:",
121+ "Your Profile": "Your Profile",
122+ "Choose Profile Image...": "Choose Profile Image...",
123+ "Choose a name": "Choose a name",
124+ "Describe yourself (if you want)": "Describe yourself (if you want)",
125+ "What whould you like to call ": "What whould you like to call ",
126+ "Confirm": "Confirm",
127+ "self assigned a display image": "self assigned a display image",
128+ "Like": "Like",
129+ "Reply": "Reply",
130+ "unfollowed ": "unfollowed ",
131+ "Untitled Gathering": "Untitled Gathering",
132+ "Error": "Error",
133+ "An error occurred while attempting to publish gathering.": "An error occurred while attempting to publish gathering.",
134+ "An error occurred while attempting to redeem invite.": "An error occurred while attempting to redeem invite.",
135+ "OK": "OK",
136+ "Close": "Close",
137+ "New Message": "New Message",
138+ "unsubscribed from ": "unsubscribed from ",
139+ "en": "en"
136140 }
locales/es.jsonView
@@ -1,5 +1,6 @@
11 {
2+ "$name": "el español",
23 "Patchwork": "Patchwork",
34 "Public": "Público",
45 "Private": "Privado",
56 "Write a public message": "Escribe un mensaje públio",
@@ -131,6 +132,9 @@
131132 "day": "día",
132133 "hour": "hora",
133134 "minute": "minutos",
134135 "second": "segundos",
135- "unsubscribed from ": "desuscrito de "
136+ "unsubscribed from ": "desuscrito de ",
137+ "en": "en",
138+ "es": "es",
139+ "ki": "ki"
136140 }
locales/ki.jsonView
@@ -1,5 +1,6 @@
11 {
2+ "$name": "कॉशुर, کأشُر",
23 "Write a public message": "پبلک پیغام لکھنے",
34 "Active Channels": "فعال",
45 "Loading": "لوڈ ہو رہا ہے",
56 "Local": "مقامی",
@@ -32,6 +33,53 @@
3233 "Write a private reply": "نجی جواب",
3334 "Write a public reply": "پبلک جواب",
3435 "Publishing...": "پبلشنگ ...",
3536 "Publish": "شائع",
36- "More Channels...": "More Channels..."
37-}
37+ "More Channels...": "More Channels...",
38+ "from now": "from now",
39+ "ago": "ago",
40+ "years": "years",
41+ "months": "months",
42+ "weeks": "weeks",
43+ "days": "days",
44+ "hours": "hours",
45+ "minutes": "minutes",
46+ "seconds": "seconds",
47+ "year": "year",
48+ "month": "month",
49+ "week": "week",
50+ "day": "day",
51+ "hour": "hour",
52+ "minute": "minute",
53+ "second": "second",
54+ "replied to this message": "replied to this message",
55+ "in reply to ": "in reply to ",
56+ "Write a private message": "Write a private message",
57+ "Edit Your Profile": "Edit Your Profile",
58+ "Click to unfollow": "Click to unfollow",
59+ "Friends": "Friends",
60+ "Following": "Following",
61+ "Follow Back": "Follow Back",
62+ "Follow": "Follow",
63+ "Followers": "Followers",
64+ "More": "More",
65+ "Gatherings": "Gatherings",
66+ "Extended Network": "Extended Network",
67+ "Settings": "Settings",
68+ "Upgrading database": "Upgrading database",
69+ "Downloading new messages": "Downloading new messages",
70+ "Indexing database": "Indexing database",
71+ "Scuttling...": "Scuttling...",
72+ " has been released.": " has been released.",
73+ " Click here to download and view more info!": " Click here to download and view more info!",
74+ "Self Assigned": "Self Assigned",
75+ "Assigned By": "Assigned By",
76+ "mentioned you": "mentioned you",
77+ "liked this message": "liked this message",
78+ "followed ": "followed ",
79+ "Channels": "Channels",
80+ "Browse All": "Browse All",
81+ "Theme": "Theme",
82+ "Language": "Language",
83+ "Filters": "Filters",
84+ " Hide following messages": " Hide following messages"
85+}
modules/page/html/render/settings.jsView
@@ -7,21 +7,23 @@
77 exports.needs = nest({
88 'settings.obs.get': 'first',
99 'settings.sync.set': 'first',
1010 'intl.sync.locales': 'first',
11- 'intl.sync.i18n': 'first'
11+ 'intl.sync.i18n': 'first',
12+ 'intl.sync.localeNames': 'first'
1213 })
1314
1415 exports.gives = nest('page.html.render')
1516
1617 exports.create = function (api) {
1718 return nest('page.html.render', function channel (path) {
1819 if (path !== '/settings') return
1920 const i18n = api.intl.sync.i18n
20-
21+
2122 const currentTheme = api.settings.obs.get('patchwork.theme')
2223 const currentLang = api.settings.obs.get('patchwork.lang')
23- const langNames = api.intl.sync.locales()
24+ const locales = api.intl.sync.locales()
25+ const localeNameLookup = api.intl.sync.localeNames()
2426 const filterFollowing = api.settings.obs.get('filters.following')
2527
2628 var prepend = [
2729 h('PageHeading', [
@@ -34,44 +36,41 @@
3436 return h('Scroller', { style: { overflow: 'auto' } }, [
3537 h('div.wrapper', [
3638 h('section.prepend', prepend),
3739 h('section.content', [
40+
3841 h('section', [
3942 h('h2', i18n('Theme')),
40- computed(currentTheme, currentTheme => {
41- return themeNames.map(name => {
42- const style = currentTheme == name
43- ? { 'margin-right': '1rem', 'border-color': 'teal' }
44- : { 'margin-right': '1rem' }
45-
46- return h('button', {
47- 'ev-click': () => api.settings.sync.set({
48- patchwork: {theme: name}
49- }),
50- style
51- }, name)
43+ h('select', {
44+ style: {
45+ 'font-size': '120%'
46+ },
47+ value: currentTheme,
48+ 'ev-change': (ev) => api.settings.sync.set({
49+ patchwork: {theme: ev.target.value}
5250 })
5351 }, [
5452 themeNames.map(name => h('option', {value: name}, [name]))
5553 ])
5654 ]),
55+
5756 h('section', [
5857 h('h2', i18n('Language')),
59- computed(currentLang, currentLang => {
60- return langNames.map(lang => {
61- const style = currentLang == lang
62- ? { 'margin-right': '1rem', 'border-color': 'teal' }
63- : { 'margin-right': '1rem' }
64-
65- return h('button', {
66- 'ev-click': () => api.settings.sync.set({
67- patchwork: {lang: lang}
68- }),
69- style
70- }, lang)
58+ h('select', {
59+ style: {
60+ 'font-size': '120%'
61+ },
62+ value: currentLang,
63+ 'ev-change': (ev) => api.settings.sync.set({
64+ patchwork: {lang: ev.target.value}
7165 })
72- })
66+ }, [
67+ locales.map(code => h('option', {value: code}, [
68+ code.toUpperCase(), ' - ', getLocaleName(code)
69+ ]))
70+ ])
7371 ]),
72+
7473 h('section', [
7574 h('h2', i18n('Filters')),
7675 h('label', [
7776 h('input', {
@@ -85,6 +84,17 @@
8584 ])
8685 ])
8786 ])
8887 ])
88+
89+ function getLocaleName (code) {
90+ var translated = i18n(code)
91+ var name = localeNameLookup[code]
92+
93+ if (name !== translated && code !== translated) {
94+ return `${name} (${translated})`
95+ } else {
96+ return name
97+ }
98+ }
8999 })
90100 }
plugs/intl/sync/i18n.jsView
@@ -1,14 +1,15 @@
11 const nest = require('depnest')
22 var { watch } = require('mutant')
3-var appRoot = require('app-root-path');
4-var i18nL = require("i18n")
3+var appRoot = require('app-root-path')
4+var i18nL = require('i18n')
55
66 exports.gives = nest('intl.sync', [
77 'locale',
88 'locales',
9+ 'localeNames',
910 'i18n',
10- 'time',
11+ 'time'
1112 ])
1213
1314 exports.needs = nest({
1415 'intl.sync.locale':'first',
@@ -28,8 +29,9 @@
2829
2930 return nest('intl.sync', {
3031 locale,
3132 locales,
33+ localeNames,
3234 i18n,
3335 time
3436 })
3537
@@ -42,9 +44,17 @@
4244 function locales (sofar = {}) {
4345 return i18nL.getLocales()
4446 }
4547
46- //Get translation
48+ function localeNames () {
49+ var names = i18nL.__l('$name')
50+ return locales().reduce((result, item, i) => {
51+ result[item] = names[i]
52+ return result
53+ }, {})
54+ }
55+
56+ //Get translation
4757 function i18n (value) {
4858 _init()
4959 return i18nL.__(value)
5060 }
@@ -79,9 +89,9 @@
7989 });
8090
8191 watch(api.settings.obs.get('patchwork.lang',navigator.language), currentLocale => {
8292 i18nL.setLocale(getSubLocal(currentLocale))
83-
93+
8494 // Only refresh if the language has already been selected once.
8595 // This will prevent the update loop
8696 if (_locale) {
8797 electron.remote.getCurrentWebContents().reloadIgnoringCache()

Built with git-ssb-web