Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix language names #580

Merged
merged 4 commits into from
Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
"eslint-plugin-prettier": "^4.0.0",
"husky": "^7.0.4",
"import-sort-style-module": "^6.0.0",
"iso-639-1": "^2.1.10",
"lemmy-js-client": "0.15.1-rc.1",
"lint-staged": "^12.1.2",
"mini-css-extract-plugin": "^2.4.5",
Expand Down
4 changes: 2 additions & 2 deletions src/shared/components/app/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { UserService, WebSocketService } from "../../services";
import {
authField,
donateLemmyUrl,
getLanguage,
getLanguages,
isBrowser,
notifyComment,
notifyPrivateMessage,
Expand Down Expand Up @@ -612,7 +612,7 @@ export class Navbar extends Component<NavbarProps, NavbarState> {
setTheme(
UserService.Instance.myUserInfo.local_user_view.local_user.theme
);
i18n.changeLanguage(getLanguage());
i18n.changeLanguage(getLanguages()[0]);
this.state.isLoggedIn = true;
this.setState(this.state);
} else if (op == UserOperation.CreateComment) {
Expand Down
4 changes: 2 additions & 2 deletions src/shared/components/common/moment-time.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component } from "inferno";
import moment from "moment";
import { i18n } from "../../i18next";
import { capitalizeFirstLetter, getMomentLanguage } from "../../utils";
import { capitalizeFirstLetter, getLanguages } from "../../utils";
import { Icon } from "./icon";

interface MomentTimeProps {
Expand All @@ -18,7 +18,7 @@ export class MomentTime extends Component<MomentTimeProps, any> {
constructor(props: any, context: any) {
super(props, context);

let lang = getMomentLanguage();
let lang = getLanguages();

moment.locale(lang);
}
Expand Down
12 changes: 4 additions & 8 deletions src/shared/components/person/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
UserOperation,
} from "lemmy-js-client";
import { Subscription } from "rxjs";
import { i18n } from "../../i18next";
import { i18n, languages } from "../../i18next";
import { UserService, WebSocketService } from "../../services";
import {
authField,
Expand All @@ -30,10 +30,8 @@ import {
elementUrl,
fetchCommunities,
fetchUsers,
getLanguage,
getNativeLanguageName,
getLanguages,
isBrowser,
languages,
personSelectName,
personToChoice,
setIsoData,
Expand Down Expand Up @@ -526,9 +524,7 @@ export class Settings extends Component<any, SettingsState> {
{languages
.sort((a, b) => a.code.localeCompare(b.code))
.map(lang => (
<option value={lang.code}>
{getNativeLanguageName(lang.code)}
</option>
<option value={lang.code}>{lang.name}</option>
))}
</select>
</div>
Expand Down Expand Up @@ -935,7 +931,7 @@ export class Settings extends Component<any, SettingsState> {

handleLangChange(i: Settings, event: any) {
i.state.saveUserSettingsForm.lang = event.target.value;
i18n.changeLanguage(getLanguage(i.state.saveUserSettingsForm.lang));
i18n.changeLanguage(getLanguages(i.state.saveUserSettingsForm.lang)[0]);
i.setState(i.state);
}

Expand Down
113 changes: 38 additions & 75 deletions src/shared/i18next.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import i18next, { i18nTyped } from "i18next";
import i18next, { i18nTyped, Resource } from "i18next";
import { ar } from "./translations/ar";
import { as } from "./translations/as";
import { bg } from "./translations/bg";
import { bn } from "./translations/bn";
import { ca } from "./translations/ca";
import { cs } from "./translations/cs";
import { cy } from "./translations/cy";
import { da } from "./translations/da";
import { de } from "./translations/de";
import { el } from "./translations/el";
Expand All @@ -18,88 +15,57 @@ import { fi } from "./translations/fi";
import { fr } from "./translations/fr";
import { ga } from "./translations/ga";
import { gl } from "./translations/gl";
import { hi } from "./translations/hi";
import { hr } from "./translations/hr";
import { hu } from "./translations/hu";
import { id } from "./translations/id";
import { it } from "./translations/it";
import { ja } from "./translations/ja";
import { ka } from "./translations/ka";
import { km } from "./translations/km";
import { ko } from "./translations/ko";
import { lt } from "./translations/lt";
import { ml } from "./translations/ml";
import { mnc } from "./translations/mnc";
import { nb_NO } from "./translations/nb_NO";
import { nl } from "./translations/nl";
import { oc } from "./translations/oc";
import { pl } from "./translations/pl";
import { pt } from "./translations/pt";
import { pt_BR } from "./translations/pt_BR";
import { ru } from "./translations/ru";
import { sk } from "./translations/sk";
import { sq } from "./translations/sq";
import { sr_Latn } from "./translations/sr_Latn";
import { sv } from "./translations/sv";
import { th } from "./translations/th";
import { tr } from "./translations/tr";
import { uk } from "./translations/uk";
import { vi } from "./translations/vi";
import { zh } from "./translations/zh";
import { zh_Hant } from "./translations/zh_Hant";
import { getLanguage } from "./utils";
import { getLanguages } from "./utils";

// https://github.com/nimbusec-oss/inferno-i18next/blob/master/tests/T.test.js#L66
const resources = {
en,
el,
eu,
eo,
es,
ka,
hi,
de,
zh,
fr,
sv,
ru,
nl,
it,
fi,
ca,
fa,
pl,
pt_BR,
ja,
gl,
tr,
hu,
uk,
sq,
km,
ga,
sr_Latn,
da,
oc,
hr,
th,
bg,
ar,
ko,
id,
nb_NO,
zh_Hant,
cy,
mnc,
sk,
vi,
pt,
bn,
ml,
cs,
as,
lt,
};
export const languages = [
{ resource: ar, code: "ar", name: "العربية" },
{ resource: bg, code: "bg", name: "Български" },
{ resource: ca, code: "ca", name: "Català" },
{ resource: cs, code: "cs", name: "Česky" },
{ resource: da, code: "da", name: "Dansk" },
{ resource: de, code: "de", name: "Deutsch" },
{ resource: el, code: "el", name: "Ελληνικά" },
{ resource: en, code: "en", name: "English" },
{ resource: eo, code: "eo", name: "Esperanto" },
{ resource: es, code: "es", name: "Español" },
{ resource: eu, code: "eu", name: "Euskara" },
{ resource: fa, code: "fa", name: "فارسی" },
{ resource: fi, code: "fi", name: "Suomi" },
{ resource: fr, code: "fr", name: "Français" },
{ resource: ga, code: "ga", name: "Gaeilge" },
{ resource: gl, code: "gl", name: "Galego" },
{ resource: hr, code: "hr", name: "Hrvatski" },
{ resource: id, code: "id", name: "Bahasa Indonesia" },
{ resource: it, code: "it", name: "Italiano" },
{ resource: ja, code: "ja", name: "日本語" },
{ resource: ko, code: "ko", name: "한국어" },
{ resource: nl, code: "nl", name: "Nederlands" },
{ resource: pl, code: "pl", name: "Polski" },
{ resource: pt, code: "pt", name: "Português" },
{ resource: pt_BR, code: "pt_BR", name: "Português (Brasil)" },
{ resource: ru, code: "ru", name: "Русский" },
{ resource: sv, code: "sv", name: "Svenska" },
{ resource: vi, code: "vi", name: "Tiếng Việt" },
{ resource: zh, code: "zh", name: "中文" },
{ resource: zh_Hant, code: "zh_Hant", name: "文言" },
];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge the different language lists in a single place for simplicity, also sort alphabetically.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is much better.


const resources: Resource = {};
languages.forEach(l => (resources[l.code] = l.resource));

function format(value: any, format: any): any {
return format === "uppercase" ? value.toUpperCase() : value;
Expand All @@ -109,14 +75,11 @@ i18next.init({
debug: false,
compatibilityJSON: "v3",
// load: 'languageOnly',

// initImmediate: false,
lng: getLanguage(),
lng: getLanguages()[0],
fallbackLng: "en",
resources,
interpolation: { format },
});

export const i18n = i18next as i18nTyped;

export { resources };
Loading