more i18n progress

This commit is contained in:
Jeremy Kauffman 2017-08-19 14:03:51 -04:00
parent 970539ffae
commit cefc882474
10 changed files with 283 additions and 340 deletions

View file

@ -346,12 +346,6 @@ export function doClearCache() {
}; };
} }
export function doChangeLanguage(newLanguage) {
return function(dispatch, getState) {
app.i18n.setLocale(newLanguage);
};
}
export function doQuit() { export function doQuit() {
return function(dispatch, getState) { return function(dispatch, getState) {
remote.app.quit(); remote.app.quit();

View file

@ -45,247 +45,56 @@ export function doSetClientSetting(key, value) {
}; };
} }
export function doResolveLanguage(locale) { export function doDownloadLanguage(langFile) {
const langs = {
aa: ["Afar", "Afar"],
ab: ["Abkhazian", "Аҧсуа"],
af: ["Afrikaans", "Afrikaans"],
ak: ["Akan", "Akana"],
am: ["Amharic", "አማርኛ"],
an: ["Aragonese", "Aragonés"],
ar: ["Arabic", "العربية"],
as: ["Assamese", "অসমীয়া"],
av: ["Avar", "Авар"],
ay: ["Aymara", "Aymar"],
az: ["Azerbaijani", "Azərbaycanca / آذربايجان"],
ba: ["Bashkir", "Башҡорт"],
be: ["Belarusian", "Беларуская"],
bg: ["Bulgarian", "Български"],
bh: ["Bihari", "भोजपुरी"],
bi: ["Bislama", "Bislama"],
bm: ["Bambara", "Bamanankan"],
bn: ["Bengali", "বাংলা"],
bo: ["Tibetan", "བོད་ཡིག / Bod skad"],
br: ["Breton", "Brezhoneg"],
bs: ["Bosnian", "Bosanski"],
ca: ["Catalan", "Català"],
ce: ["Chechen", "Нохчийн"],
ch: ["Chamorro", "Chamoru"],
co: ["Corsican", "Corsu"],
cr: ["Cree", "Nehiyaw"],
cs: ["Czech", "Česky"],
cu: ["Old Church Slavonic / Old Bulgarian", "словѣньскъ / slověnĭskŭ"],
cv: ["Chuvash", "Чăваш"],
cy: ["Welsh", "Cymraeg"],
da: ["Danish", "Dansk"],
de: ["German", "Deutsch"],
dv: ["Divehi", "ދިވެހިބަސް"],
dz: ["Dzongkha", "ཇོང་ཁ"],
ee: ["Ewe", "Ɛʋɛ"],
el: ["Greek", "Ελληνικά"],
en: ["English", "English"],
eo: ["Esperanto", "Esperanto"],
es: ["Spanish", "Español"],
et: ["Estonian", "Eesti"],
eu: ["Basque", "Euskara"],
fa: ["Persian", "فارسی"],
ff: ["Peul", "Fulfulde"],
fi: ["Finnish", "Suomi"],
fj: ["Fijian", "Na Vosa Vakaviti"],
fo: ["Faroese", "Føroyskt"],
fr: ["French", "Français"],
fy: ["West Frisian", "Frysk"],
ga: ["Irish", "Gaeilge"],
gd: ["Scottish Gaelic", "Gàidhlig"],
gl: ["Galician", "Galego"],
gn: ["Guarani", "Avañe'ẽ"],
gu: ["Gujarati", "ગુજરાતી"],
gv: ["Manx", "Gaelg"],
ha: ["Hausa", "هَوُسَ"],
he: ["Hebrew", "עברית"],
hi: ["Hindi", "हिन्दी"],
ho: ["Hiri Motu", "Hiri Motu"],
hr: ["Croatian", "Hrvatski"],
ht: ["Haitian", "Krèyol ayisyen"],
hu: ["Hungarian", "Magyar"],
hy: ["Armenian", "Հայերեն"],
hz: ["Herero", "Otsiherero"],
ia: ["Interlingua", "Interlingua"],
id: ["Indonesian", "Bahasa Indonesia"],
ie: ["Interlingue", "Interlingue"],
ig: ["Igbo", "Igbo"],
ii: ["Sichuan Yi", "ꆇꉙ / 四川彝语"],
ik: ["Inupiak", "Iñupiak"],
io: ["Ido", "Ido"],
is: ["Icelandic", "Íslenska"],
it: ["Italian", "Italiano"],
iu: ["Inuktitut", "ᐃᓄᒃᑎᑐᑦ"],
ja: ["Japanese", "日本語"],
jv: ["Javanese", "Basa Jawa"],
ka: ["Georgian", "ქართული"],
kg: ["Kongo", "KiKongo"],
ki: ["Kikuyu", "Gĩkũyũ"],
kj: ["Kuanyama", "Kuanyama"],
kk: ["Kazakh", "Қазақша"],
kl: ["Greenlandic", "Kalaallisut"],
km: ["Cambodian", "ភាសាខ្មែរ"],
kn: ["Kannada", "ಕನ್ನಡ"],
ko: ["Korean", "한국어"],
kr: ["Kanuri", "Kanuri"],
ks: ["Kashmiri", "कश्मीरी / كشميري"],
ku: ["Kurdish", "Kurdî / كوردی"],
kv: ["Komi", "Коми"],
kw: ["Cornish", "Kernewek"],
ky: ["Kirghiz", "Kırgızca / Кыргызча"],
la: ["Latin", "Latina"],
lb: ["Luxembourgish", "Lëtzebuergesch"],
lg: ["Ganda", "Luganda"],
li: ["Limburgian", "Limburgs"],
ln: ["Lingala", "Lingála"],
lo: ["Laotian", "ລາວ / Pha xa lao"],
lt: ["Lithuanian", "Lietuvių"],
lv: ["Latvian", "Latviešu"],
mg: ["Malagasy", "Malagasy"],
mh: ["Marshallese", "Kajin Majel / Ebon"],
mi: ["Maori", "Māori"],
mk: ["Macedonian", "Македонски"],
ml: ["Malayalam", "മലയാളം"],
mn: ["Mongolian", "Монгол"],
mo: ["Moldovan", "Moldovenească"],
mr: ["Marathi", "मराठी"],
ms: ["Malay", "Bahasa Melayu"],
mt: ["Maltese", "bil-Malti"],
my: ["Burmese", "Myanmasa"],
na: ["Nauruan", "Dorerin Naoero"],
nd: ["North Ndebele", "Sindebele"],
ne: ["Nepali", "नेपाली"],
ng: ["Ndonga", "Oshiwambo"],
nl: ["Dutch", "Nederlands"],
nn: ["Norwegian Nynorsk", "Norsk (nynorsk)"],
no: ["Norwegian", "Norsk (bokmål / riksmål)"],
nr: ["South Ndebele", "isiNdebele"],
nv: ["Navajo", "Diné bizaad"],
ny: ["Chichewa", "Chi-Chewa"],
oc: ["Occitan", "Occitan"],
oj: ["Ojibwa", "ᐊᓂᔑᓈᐯᒧᐎᓐ / Anishinaabemowin"],
om: ["Oromo", "Oromoo"],
or: ["Oriya", "ଓଡ଼ିଆ"],
os: ["Ossetian / Ossetic", "Иронау"],
pa: ["Panjabi / Punjabi", "ਪੰਜਾਬੀ / पंजाबी / پنجابي"],
pi: ["Pali", "Pāli / पाऴि"],
pl: ["Polish", "Polski"],
ps: ["Pashto", "پښتو"],
pt: ["Portuguese", "Português"],
qu: ["Quechua", "Runa Simi"],
rm: ["Raeto Romance", "Rumantsch"],
rn: ["Kirundi", "Kirundi"],
ro: ["Romanian", "Română"],
ru: ["Russian", "Русский"],
rw: ["Rwandi", "Kinyarwandi"],
sa: ["Sanskrit", "संस्कृतम्"],
sc: ["Sardinian", "Sardu"],
sd: ["Sindhi", "सिनधि"],
se: ["Northern Sami", "Sámegiella"],
sg: ["Sango", "Sängö"],
sh: ["Serbo-Croatian", "Srpskohrvatski / Српскохрватски"],
si: ["Sinhalese", "සිංහල"],
sk: ["Slovak", "Slovenčina"],
sl: ["Slovenian", "Slovenščina"],
sm: ["Samoan", "Gagana Samoa"],
sn: ["Shona", "chiShona"],
so: ["Somalia", "Soomaaliga"],
sq: ["Albanian", "Shqip"],
sr: ["Serbian", "Српски"],
ss: ["Swati", "SiSwati"],
st: ["Southern Sotho", "Sesotho"],
su: ["Sundanese", "Basa Sunda"],
sv: ["Swedish", "Svenska"],
sw: ["Swahili", "Kiswahili"],
ta: ["Tamil", "தமிழ்"],
te: ["Telugu", "తెలుగు"],
tg: ["Tajik", "Тоҷикӣ"],
th: ["Thai", "ไทย / Phasa Thai"],
ti: ["Tigrinya", "ትግርኛ"],
tk: ["Turkmen", "Туркмен / تركمن"],
tl: ["Tagalog / Filipino", "Tagalog"],
tn: ["Tswana", "Setswana"],
to: ["Tonga", "Lea Faka-Tonga"],
tr: ["Turkish", "Türkçe"],
ts: ["Tsonga", "Xitsonga"],
tt: ["Tatar", "Tatarça"],
tw: ["Twi", "Twi"],
ty: ["Tahitian", "Reo Mā`ohi"],
ug: ["Uyghur", "Uyƣurqə / ئۇيغۇرچە"],
uk: ["Ukrainian", "Українська"],
ur: ["Urdu", "اردو"],
uz: ["Uzbek", "Ўзбек"],
ve: ["Venda", "Tshivenḓa"],
vi: ["Vietnamese", "Tiếng Việt"],
vo: ["Volapük", "Volapük"],
wa: ["Walloon", "Walon"],
wo: ["Wolof", "Wollof"],
xh: ["Xhosa", "isiXhosa"],
yi: ["Yiddish", "ייִדיש"],
yo: ["Yoruba", "Yorùbá"],
za: ["Zhuang", "Cuengh / Tôô / 壮语"],
zh: ["Chinese", "中文"],
zu: ["Zulu", "isiZulu"],
};
const lang = locale.substring(0, 2);
return {
type: types.LANGUAGE_RESOLVED,
data: { key: locale, value: `${langs[lang][0]} (${langs[lang][1]})` },
};
}
export function doDownloadLanguage(lang, destinationPath) {
return function(dispatch, getState) { return function(dispatch, getState) {
const plainLanguage = lang.replace(".json", ""); const destinationPath = `app/locales/${langFile}`;
const language = langFile.replace(".json", "");
const req = http.get(
{
headers: {
"Content-Type": "text/html",
},
host: "i18n.lbry.io",
path: `/langs/${langFile}`,
},
response => {
if (response.statusCode === 200) {
const file = fs.createWriteStream(destinationPath);
dispatch({ file.on("error", errorHandler);
type: types.DOWNLOAD_LANGUAGE_STARTED,
data: plainLanguage,
});
return new Promise((resolve, reject) => {
const file = fs.createWriteStream(destinationPath);
const req = http.request(
`http://i18n.lbry.io/langs/${lang}`,
response => {
file.on("finish", () => { file.on("finish", () => {
file.close(); file.close();
// push to our local list // push to our local list
dispatch({ dispatch({
type: types.DOWNLOAD_LANGUAGE_SUCCEEDED, type: types.DOWNLOAD_LANGUAGE_SUCCEEDED,
data: plainLanguage, data: { language: language },
}); });
resolve();
}); });
response.pipe(file); response.pipe(file);
} else {
errorHandler(new Error("Language request failed."));
} }
); }
);
const errorHandler = err => { const errorHandler = err => {
if (file) { fs.unlink(destinationPath, () => {}); // Delete the file async. (But we don't check the result)
file.close();
}
fs.unlink(destinationPath); // Delete the file async. (But we don't check the result) dispatch({
dispatch({ type: types.DOWNLOAD_LANGUAGE_FAILED,
type: types.DOWNLOAD_LANGUAGE_FAILED, data: { language },
data: plainLanguage, });
}); };
reject(err);
};
req.on("error", errorHandler);
file.on("error", errorHandler);
req.end(); req.setTimeout(30000, function() {
req.abort();
}); });
req.on("error", errorHandler);
req.end();
}; };
} }
@ -295,45 +104,34 @@ export function doDownloadLanguages() {
fs.mkdirSync(app.i18n.directory); fs.mkdirSync(app.i18n.directory);
} }
dispatch({ const req = http.request({ host: "i18n.lbry.io", path: "/" }, response => {
type: types.DOWNLOAD_LANGUAGES_STARTED, let str = "";
data: {},
});
return new Promise((resolve, reject) => { response.on("data", chunk => {
const req = http.request( str += chunk;
{ host: "i18n.lbry.io", path: "/" },
response => {
let str = "";
response.on("data", chunk => {
str += chunk;
});
response.on("end", () => {
const files = JSON.parse(str);
const actions = [];
files.forEach(file => {
actions.push(doDownloadLanguage(file, `app/locales/${file}`));
});
dispatch(batchActions(...actions));
dispatch({
type: types.DOWNLOAD_LANGUAGES_COMPLETED,
data: {},
});
resolve();
});
}
);
req.on("error", err => {
reject(err);
}); });
req.end(); response.on("end", () => {
const files = JSON.parse(str);
const actions = [];
files.forEach(file => {
actions.push(doDownloadLanguage(file));
});
dispatch(batchActions(...actions));
});
}); });
req.on("error", err => {
throw err; //this ought to be cleanly handled
});
req.end();
};
}
export function doChangeLanguage(language) {
return function(dispatch, getState) {
app.i18n.setLocale(language);
}; };
} }

View file

@ -115,9 +115,5 @@ export const CLAIM_REWARD_CLEAR_ERROR = "CLAIM_REWARD_CLEAR_ERROR";
export const FETCH_REWARD_CONTENT_COMPLETED = "FETCH_REWARD_CONTENT_COMPLETED"; export const FETCH_REWARD_CONTENT_COMPLETED = "FETCH_REWARD_CONTENT_COMPLETED";
//Language //Language
export const LANGUAGE_RESOLVED = "LANGUAGE_RESOLVED";
export const DOWNLOAD_LANGUAGE_STARTED = "DOWNLOAD_LANGUAGE_STARTED";
export const DOWNLOAD_LANGUAGE_SUCCEEDED = "DOWNLOAD_LANGUAGE_SUCCEEDED"; export const DOWNLOAD_LANGUAGE_SUCCEEDED = "DOWNLOAD_LANGUAGE_SUCCEEDED";
export const DOWNLOAD_LANGUAGE_FAILED = "DOWNLOAD_LANGUAGE_FAILED"; export const DOWNLOAD_LANGUAGE_FAILED = "DOWNLOAD_LANGUAGE_FAILED";
export const DOWNLOAD_LANGUAGES_STARTED = "DOWNLOAD_LANGUAGES_STARTED";
export const DOWNLOAD_LANGUAGES_COMPLETED = "DOWNLOAD_LANGUAGES_COMPLETED";

View file

@ -0,0 +1,187 @@
const LANGUAGES = {
aa: ["Afar", "Afar"],
ab: ["Abkhazian", "Аҧсуа"],
af: ["Afrikaans", "Afrikaans"],
ak: ["Akan", "Akana"],
am: ["Amharic", "አማርኛ"],
an: ["Aragonese", "Aragonés"],
ar: ["Arabic", "العربية"],
as: ["Assamese", "অসমীয়া"],
av: ["Avar", "Авар"],
ay: ["Aymara", "Aymar"],
az: ["Azerbaijani", "Azərbaycanca / آذربايجان"],
ba: ["Bashkir", "Башҡорт"],
be: ["Belarusian", "Беларуская"],
bg: ["Bulgarian", "Български"],
bh: ["Bihari", "भोजपुरी"],
bi: ["Bislama", "Bislama"],
bm: ["Bambara", "Bamanankan"],
bn: ["Bengali", "বাংলা"],
bo: ["Tibetan", "བོད་ཡིག / Bod skad"],
br: ["Breton", "Brezhoneg"],
bs: ["Bosnian", "Bosanski"],
ca: ["Catalan", "Català"],
ce: ["Chechen", "Нохчийн"],
ch: ["Chamorro", "Chamoru"],
co: ["Corsican", "Corsu"],
cr: ["Cree", "Nehiyaw"],
cs: ["Czech", "Česky"],
cu: ["Old Church Slavonic / Old Bulgarian", "словѣньскъ / slověnĭskŭ"],
cv: ["Chuvash", "Чăваш"],
cy: ["Welsh", "Cymraeg"],
da: ["Danish", "Dansk"],
de: ["German", "Deutsch"],
dv: ["Divehi", "ދިވެހިބަސް"],
dz: ["Dzongkha", "ཇོང་ཁ"],
ee: ["Ewe", "Ɛʋɛ"],
el: ["Greek", "Ελληνικά"],
en: ["English", "English"],
eo: ["Esperanto", "Esperanto"],
es: ["Spanish", "Español"],
et: ["Estonian", "Eesti"],
eu: ["Basque", "Euskara"],
fa: ["Persian", "فارسی"],
ff: ["Peul", "Fulfulde"],
fi: ["Finnish", "Suomi"],
fj: ["Fijian", "Na Vosa Vakaviti"],
fo: ["Faroese", "Føroyskt"],
fr: ["French", "Français"],
fy: ["West Frisian", "Frysk"],
ga: ["Irish", "Gaeilge"],
gd: ["Scottish Gaelic", "Gàidhlig"],
gl: ["Galician", "Galego"],
gn: ["Guarani", "Avañe'ẽ"],
gu: ["Gujarati", "ગુજરાતી"],
gv: ["Manx", "Gaelg"],
ha: ["Hausa", "هَوُسَ"],
he: ["Hebrew", "עברית"],
hi: ["Hindi", "हिन्दी"],
ho: ["Hiri Motu", "Hiri Motu"],
hr: ["Croatian", "Hrvatski"],
ht: ["Haitian", "Krèyol ayisyen"],
hu: ["Hungarian", "Magyar"],
hy: ["Armenian", "Հայերեն"],
hz: ["Herero", "Otsiherero"],
ia: ["Interlingua", "Interlingua"],
id: ["Indonesian", "Bahasa Indonesia"],
ie: ["Interlingue", "Interlingue"],
ig: ["Igbo", "Igbo"],
ii: ["Sichuan Yi", "ꆇꉙ / 四川彝语"],
ik: ["Inupiak", "Iñupiak"],
io: ["Ido", "Ido"],
is: ["Icelandic", "Íslenska"],
it: ["Italian", "Italiano"],
iu: ["Inuktitut", "ᐃᓄᒃᑎᑐᑦ"],
ja: ["Japanese", "日本語"],
jv: ["Javanese", "Basa Jawa"],
ka: ["Georgian", "ქართული"],
kg: ["Kongo", "KiKongo"],
ki: ["Kikuyu", "Gĩkũyũ"],
kj: ["Kuanyama", "Kuanyama"],
kk: ["Kazakh", "Қазақша"],
kl: ["Greenlandic", "Kalaallisut"],
km: ["Cambodian", "ភាសាខ្មែរ"],
kn: ["Kannada", "ಕನ್ನಡ"],
ko: ["Korean", "한국어"],
kr: ["Kanuri", "Kanuri"],
ks: ["Kashmiri", "कश्मीरी / كشميري"],
ku: ["Kurdish", "Kurdî / كوردی"],
kv: ["Komi", "Коми"],
kw: ["Cornish", "Kernewek"],
ky: ["Kirghiz", "Kırgızca / Кыргызча"],
la: ["Latin", "Latina"],
lb: ["Luxembourgish", "Lëtzebuergesch"],
lg: ["Ganda", "Luganda"],
li: ["Limburgian", "Limburgs"],
ln: ["Lingala", "Lingála"],
lo: ["Laotian", "ລາວ / Pha xa lao"],
lt: ["Lithuanian", "Lietuvių"],
lv: ["Latvian", "Latviešu"],
mg: ["Malagasy", "Malagasy"],
mh: ["Marshallese", "Kajin Majel / Ebon"],
mi: ["Maori", "Māori"],
mk: ["Macedonian", "Македонски"],
ml: ["Malayalam", "മലയാളം"],
mn: ["Mongolian", "Монгол"],
mo: ["Moldovan", "Moldovenească"],
mr: ["Marathi", "मराठी"],
ms: ["Malay", "Bahasa Melayu"],
mt: ["Maltese", "bil-Malti"],
my: ["Burmese", "Myanmasa"],
na: ["Nauruan", "Dorerin Naoero"],
nd: ["North Ndebele", "Sindebele"],
ne: ["Nepali", "नेपाली"],
ng: ["Ndonga", "Oshiwambo"],
nl: ["Dutch", "Nederlands"],
nn: ["Norwegian Nynorsk", "Norsk (nynorsk)"],
no: ["Norwegian", "Norsk (bokmål / riksmål)"],
nr: ["South Ndebele", "isiNdebele"],
nv: ["Navajo", "Diné bizaad"],
ny: ["Chichewa", "Chi-Chewa"],
oc: ["Occitan", "Occitan"],
oj: ["Ojibwa", "ᐊᓂᔑᓈᐯᒧᐎᓐ / Anishinaabemowin"],
om: ["Oromo", "Oromoo"],
or: ["Oriya", "ଓଡ଼ିଆ"],
os: ["Ossetian / Ossetic", "Иронау"],
pa: ["Panjabi / Punjabi", "ਪੰਜਾਬੀ / पंजाबी / پنجابي"],
pi: ["Pali", "Pāli / पाऴि"],
pl: ["Polish", "Polski"],
ps: ["Pashto", "پښتو"],
pt: ["Portuguese", "Português"],
qu: ["Quechua", "Runa Simi"],
rm: ["Raeto Romance", "Rumantsch"],
rn: ["Kirundi", "Kirundi"],
ro: ["Romanian", "Română"],
ru: ["Russian", "Русский"],
rw: ["Rwandi", "Kinyarwandi"],
sa: ["Sanskrit", "संस्कृतम्"],
sc: ["Sardinian", "Sardu"],
sd: ["Sindhi", "सिनधि"],
se: ["Northern Sami", "Sámegiella"],
sg: ["Sango", "Sängö"],
sh: ["Serbo-Croatian", "Srpskohrvatski / Српскохрватски"],
si: ["Sinhalese", "සිංහල"],
sk: ["Slovak", "Slovenčina"],
sl: ["Slovenian", "Slovenščina"],
sm: ["Samoan", "Gagana Samoa"],
sn: ["Shona", "chiShona"],
so: ["Somalia", "Soomaaliga"],
sq: ["Albanian", "Shqip"],
sr: ["Serbian", "Српски"],
ss: ["Swati", "SiSwati"],
st: ["Southern Sotho", "Sesotho"],
su: ["Sundanese", "Basa Sunda"],
sv: ["Swedish", "Svenska"],
sw: ["Swahili", "Kiswahili"],
ta: ["Tamil", "தமிழ்"],
te: ["Telugu", "తెలుగు"],
tg: ["Tajik", "Тоҷикӣ"],
th: ["Thai", "ไทย / Phasa Thai"],
ti: ["Tigrinya", "ትግርኛ"],
tk: ["Turkmen", "Туркмен / تركمن"],
tl: ["Tagalog / Filipino", "Tagalog"],
tn: ["Tswana", "Setswana"],
to: ["Tonga", "Lea Faka-Tonga"],
tr: ["Turkish", "Türkçe"],
ts: ["Tsonga", "Xitsonga"],
tt: ["Tatar", "Tatarça"],
tw: ["Twi", "Twi"],
ty: ["Tahitian", "Reo Mā`ohi"],
ug: ["Uyghur", "Uyƣurqə / ئۇيغۇرچە"],
uk: ["Ukrainian", "Українська"],
ur: ["Urdu", "اردو"],
uz: ["Uzbek", "Ўзбек"],
ve: ["Venda", "Tshivenḓa"],
vi: ["Vietnamese", "Tiếng Việt"],
vo: ["Volapük", "Volapük"],
wa: ["Walloon", "Walon"],
wo: ["Wolof", "Wollof"],
xh: ["Xhosa", "isiXhosa"],
yi: ["Yiddish", "ייִדיש"],
yo: ["Yoruba", "Yorùbá"],
za: ["Zhuang", "Cuengh / Tôô / 壮语"],
zh: ["Chinese", "中文"],
zu: ["Zulu", "isiZulu"],
};
export default LANGUAGES;

View file

@ -10,8 +10,6 @@ import { doChangePath, doNavigate, doDaemonReady } from "actions/app";
import { doDownloadLanguages } from "actions/settings"; import { doDownloadLanguages } from "actions/settings";
import { toQueryString } from "util/query_params"; import { toQueryString } from "util/query_params";
import * as types from "constants/action_types"; import * as types from "constants/action_types";
import fs from "fs";
import http from "http";
const env = ENV; const env = ENV;
const { remote, ipcRenderer, shell } = require("electron"); const { remote, ipcRenderer, shell } = require("electron");

View file

@ -1,16 +1,15 @@
import React from "react"; import React from "react";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { doClearCache, doChangeLanguage } from "actions/app"; import { doClearCache } from "actions/app";
import { import {
doSetDaemonSetting, doSetDaemonSetting,
doSetClientSetting, doSetClientSetting,
doResolveLanguage, doChangeLanguage,
} from "actions/settings"; } from "actions/settings";
import { import {
selectDaemonSettings, selectDaemonSettings,
selectShowNsfw, selectShowNsfw,
selectLocalLanguages, selectLanguages,
selectResolvedLanguages,
} from "selectors/settings"; } from "selectors/settings";
import { selectCurrentLanguage } from "selectors/app"; import { selectCurrentLanguage } from "selectors/app";
import SettingsPage from "./view"; import SettingsPage from "./view";
@ -19,8 +18,7 @@ const select = state => ({
daemonSettings: selectDaemonSettings(state), daemonSettings: selectDaemonSettings(state),
showNsfw: selectShowNsfw(state), showNsfw: selectShowNsfw(state),
language: selectCurrentLanguage(state), language: selectCurrentLanguage(state),
localLanguages: selectLocalLanguages(state), languages: selectLanguages(state),
resolvedLanguages: selectResolvedLanguages(state),
}); });
const perform = dispatch => ({ const perform = dispatch => ({
@ -28,7 +26,6 @@ const perform = dispatch => ({
clearCache: () => dispatch(doClearCache()), clearCache: () => dispatch(doClearCache()),
setClientSetting: (key, value) => dispatch(doSetClientSetting(key, value)), setClientSetting: (key, value) => dispatch(doSetClientSetting(key, value)),
changeLanguage: newLanguage => dispatch(doChangeLanguage(newLanguage)), changeLanguage: newLanguage => dispatch(doChangeLanguage(newLanguage)),
resolveLanguage: lang => dispatch(doResolveLanguage(lang)),
}); });
export default connect(select, perform)(SettingsPage); export default connect(select, perform)(SettingsPage);

View file

@ -24,13 +24,6 @@ class SettingsPage extends React.PureComponent {
}; };
} }
componentWillMount() {
const { localLanguages, resolveLanguage } = this.props;
localLanguages.forEach(lang => {
resolveLanguage(lang);
});
}
clearCache() { clearCache() {
this.setState({ this.setState({
clearingCache: true, clearingCache: true,
@ -107,21 +100,10 @@ class SettingsPage extends React.PureComponent {
this.props.changeLanguage(e.target.value); this.props.changeLanguage(e.target.value);
} }
// onLanguageChange(language) {
// lbry.setClientSetting('language', language);
// i18n.setLocale(language);
// this.setState({language: language})
// }
onShowUnavailableChange(event) {} onShowUnavailableChange(event) {}
render() { render() {
const { const { daemonSettings, language, languages } = this.props;
daemonSettings,
language,
localLanguages,
resolvedLanguages,
} = this.props;
if (!daemonSettings || Object.keys(daemonSettings).length === 0) { if (!daemonSettings || Object.keys(daemonSettings).length === 0) {
return ( return (
@ -140,25 +122,22 @@ class SettingsPage extends React.PureComponent {
<div className="card__content"> <div className="card__content">
<div className="form-row"> <div className="form-row">
<FormField <FormField
type="radio" type="select"
name="language" name="language"
label={__("English")}
onChange={this.onLanguageChange.bind(this)} onChange={this.onLanguageChange.bind(this)}
defaultChecked={language == "en"} >
/> <option value="en">{__("English")}</option>
{Object.keys(languages).map(dLang =>
<option
key={dLang}
selected={dLang == language ? "selected" : null}
value={language}
>
{languages[dLang]}
</option>
)}
</FormField>
</div> </div>
{localLanguages.map(dLang =>
<div key={dLang} className="form-row">
<FormField
type="radio"
name="language"
key={dLang}
label={resolvedLanguages[dLang]}
onChange={this.onLanguageChange.bind(this)}
defaultChecked={language == dLang}
/>
</div>
)}
</div> </div>
</section> </section>
<section className="card"> <section className="card">

View file

@ -1,4 +1,5 @@
import * as types from "constants/action_types"; import * as types from "constants/action_types";
import LANGUAGES from "constants/languages";
import lbry from "lbry"; import lbry from "lbry";
const reducers = {}; const reducers = {};
@ -7,6 +8,7 @@ const defaultState = {
showNsfw: lbry.getClientSetting("showNsfw"), showNsfw: lbry.getClientSetting("showNsfw"),
language: lbry.getClientSetting("language"), language: lbry.getClientSetting("language"),
}, },
languages: {},
}; };
reducers[types.DAEMON_SETTINGS_RECEIVED] = function(state, action) { reducers[types.DAEMON_SETTINGS_RECEIVED] = function(state, action) {
@ -27,28 +29,25 @@ reducers[types.CLIENT_SETTING_CHANGED] = function(state, action) {
}; };
reducers[types.DOWNLOAD_LANGUAGE_SUCCEEDED] = function(state, action) { reducers[types.DOWNLOAD_LANGUAGE_SUCCEEDED] = function(state, action) {
const localLanguages = [].concat( const languages = Object.assign({}, state.languages);
state.localLanguages ? state.localLanguages : [] const language = action.data.language;
);
const language = action.data; const langCode = language.substring(0, 2);
if (localLanguages.indexOf(language) === -1) {
localLanguages.push(language); if (LANGUAGES[langCode]) {
languages[langCode] =
LANGUAGES[langCode][0] + " (" + LANGUAGES[langCode][1] + ")";
} else {
languages[langCode] = langCode;
} }
return Object.assign({}, state, { return Object.assign({}, state, { languages });
localLanguages,
});
}; };
reducers[types.LANGUAGE_RESOLVED] = function(state, action) { reducers[types.DOWNLOAD_LANGUAGE_FAILED] = function(state, action) {
const { key, value } = action.data; const languages = Object.assign({}, state.languages);
const resolvedLanguages = Object.assign({}, state.resolvedLanguages); delete languages[action.data.language];
return Object.assign({}, state, { languages });
resolvedLanguages[key] = value;
return Object.assign({}, state, {
resolvedLanguages,
});
}; };
export default function reducer(state = defaultState, action) { export default function reducer(state = defaultState, action) {

View file

@ -220,7 +220,7 @@ export const selectBadgeNumber = createSelector(
export const selectCurrentLanguage = createSelector( export const selectCurrentLanguage = createSelector(
_selectState, _selectState,
() => lbry.getClientSetting("language") || "en" () => app.i18n.getLocale() || "en"
); );
export const selectPathAfterAuth = createSelector( export const selectPathAfterAuth = createSelector(

View file

@ -22,12 +22,7 @@ export const selectShowNsfw = createSelector(
clientSettings => !!clientSettings.showNsfw clientSettings => !!clientSettings.showNsfw
); );
export const selectLocalLanguages = createSelector( export const selectLanguages = createSelector(
_selectState, _selectState,
state => state.localLanguages || [] state => state.languages || {}
);
export const selectResolvedLanguages = createSelector(
_selectState,
state => state.resolvedLanguages || {}
); );