Localization testing mostly done.

This commit is contained in:
Dessalines 2019-08-08 22:09:36 -07:00
parent 50ee0e9d82
commit 093bc00ff7
7 changed files with 285 additions and 151 deletions

View file

@ -23,10 +23,10 @@
"autosize": "^4.0.2", "autosize": "^4.0.2",
"classcat": "^1.1.3", "classcat": "^1.1.3",
"dotenv": "^6.1.0", "dotenv": "^6.1.0",
"inferno": "^7.0.1",
"inferno-router": "^7.0.1",
"i18next": "^17.0.9", "i18next": "^17.0.9",
"inferno": "^7.0.1",
"inferno-i18next": "nimbusec-oss/inferno-i18next", "inferno-i18next": "nimbusec-oss/inferno-i18next",
"inferno-router": "^7.0.1",
"js-cookie": "^2.2.0", "js-cookie": "^2.2.0",
"jwt-decode": "^2.2.0", "jwt-decode": "^2.2.0",
"markdown-it": "^8.4.2", "markdown-it": "^8.4.2",

View file

@ -1,5 +1,7 @@
import { Component } from 'inferno'; import { Component } from 'inferno';
import * as moment from 'moment'; import * as moment from 'moment';
import 'moment/locale/de.js';
import { getLanguage } from '../utils';
import { i18n } from '../i18next'; import { i18n } from '../i18next';
interface MomentTimeProps { interface MomentTimeProps {
@ -14,6 +16,8 @@ export class MomentTime extends Component<MomentTimeProps, any> {
constructor(props: any, context: any) { constructor(props: any, context: any) {
super(props, context); super(props, context);
// console.log(moment.locales());
moment.locale(getLanguage());
} }
render() { render() {

View file

@ -1,154 +1,14 @@
import * as i18n from 'i18next'; import * as i18n from 'i18next';
import { getLanguage } from './utils';
import { en } from './translations/en';
import { de } from './translations/de';
// https://github.com/nimbusec-oss/inferno-i18next/blob/master/tests/T.test.js#L66 // https://github.com/nimbusec-oss/inferno-i18next/blob/master/tests/T.test.js#L66
//
// TODO don't forget to add moment locales for new languages. // TODO don't forget to add moment locales for new languages.
const resources = { const resources = {
en: { en: en,
translation: { de: de,
post: 'post', }
edit: 'edit',
reply: 'reply',
cancel: 'Cancel',
unlock: 'unlock',
lock: 'lock',
link: 'link',
mod: 'mod',
mods: 'mods',
moderates: 'Moderates',
admin: 'admin',
admins: 'admins',
modlog: 'Modlog',
remove: 'remove',
removed: 'removed',
locked: 'locked',
reason: 'Reason',
remove_as_mod: 'remove as mod',
appoint_as_mod: 'appoint as mod',
remove_as_admin: 'remove as admin',
appoint_as_admin: 'appoint as admin',
mark_as_read: 'mark as read',
mark_as_unread: 'mark as unread',
remove_comment: 'Remove Comment',
remove_community: 'Remove Community',
delete: 'delete',
deleted: 'deleted',
restore: 'restore',
ban: 'ban',
unban: 'unban',
ban_from_site: 'ban from site',
unban_from_site: 'unban from site',
save: 'save',
unsave: 'unsave',
create: 'create',
subscribed_to_communities:'Subscribed to <1>communities</1>',
create_a_community: 'Create a community',
create_community: 'Create Community',
create_a_post: 'Create a post',
create_post: 'Create Post',
trending_communities:'Trending <1>communities</1>',
number_of_users:'{{count}} Users',
number_of_subscribers:'{{count}} Subscribers',
number_of_posts:'{{count}} Posts',
number_of_comments:'{{count}} Comments',
number_of_points:'{{count}} Points',
powered_by: 'Powered by',
landing_0: 'Lemmy is a <1>link aggregator</1> / reddit alternative, intended to work in the <2>fediverse</2>.<3></3>Its self-hostable, has live-updating comment threads, and is tiny (<4>~80kB</4>). Federation into the ActivityPub network is on the roadmap. <5></5>This is a <6>very early beta version</6>, and a lot of features are currently broken or missing. <7></7>Suggest new features or report bugs <8>here.</8><9></9>Made with <10>Rust</10>, <11>Actix</11>, <12>Inferno</12>, <13>Typescript</13>.',
list_of_communities: 'List of communities',
name: 'Name',
title: 'Title',
category: 'Category',
subscribers: 'Subscribers',
both: 'Both',
posts: 'Posts',
comments: 'Comments',
saved: 'Saved',
unsubscribe: 'Unsubscribe',
subscribe: 'Subscribe',
prev: 'Prev',
next: 'Next',
sidebar: 'Sidebar',
community_reqs: 'lowercase, underscores, and no spaces.',
sort_type: 'Sort type',
hot: 'Hot',
new: 'New',
top_day: 'Top day',
week: 'Week',
month: 'Month',
year: 'Year',
all: 'All',
top: 'Top',
api: 'API',
sponsors: 'Sponsors',
sponsors_of_lemmy: 'Sponsors of Lemmy',
sponsor_message: 'Lemmy is free, <1>open-source</1> software, meaning no advertising, monetizing, or venture capital, ever. Your donations directly support full-time development of the project. Thank you to the following people:',
support_on_patreon: 'Support on Patreon',
general_sponsors:'General Sponsors are those that pledged $10 to $39 to Lemmy.',
bitcoin: 'Bitcoin',
ethereum: 'Ethereum',
code: 'Code',
inbox: 'Inbox',
inbox_for: 'Inbox for <1>{{user}}</1>',
mark_all_as_read: 'mark all as read',
type: 'Type',
unread: 'Unread',
reply_sent: 'Reply sent',
communities: 'Communities',
search: 'Search',
overview: 'Overview',
view: 'View',
logout: 'Logout',
login_sign_up: 'Login / Sign up',
notifications_error: 'Desktop notifications not available in your browser. Try Firefox or Chrome.',
unread_messages: 'Unread Messages',
email_or_username: 'Email or Username',
password: 'Password',
verify_password: 'Verify Password',
login: 'Login',
sign_up: 'Sign Up',
username: 'Username',
email: 'Email',
optional: 'Optional',
url: 'URL',
body: 'Body',
copy_suggested_title: 'copy suggested title: {{title}}',
related_posts: 'These posts might be related',
community: 'Community',
expand_here: 'Expand here',
remove_post: 'Remove Post',
no_posts: 'No Posts.',
subscribe_to_communities: 'Subscribe to some <1>communities</1>.',
chat: 'Chat',
no_results: 'No results.',
setup: 'Setup',
lemmy_instance_setup: 'Lemmy Instance Setup',
setup_admin: 'Set Up Site Administrator',
your_site: 'your site',
modified: 'modified',
foo: 'foo',
bar: '<1>bar</1>',
baz: '<1>{{count}}</1>',
qux: 'qux<1></1>',
qux_plural: 'quxes<1></1>',
quux: '<1>{{name, uppercase}}</1>',
userMessagesUnread: 'Hello <1>{{name}}</1>, you have {{count}} unread messages. <3>Go to messages</3>.',
userMessagesUnread_plural: 'Hello <1>{{name}}</1>, you have {{count}} unread messages. <3>Go to messages</3>.'
},
},
};
function format(value: any, format: any, lng: any) { function format(value: any, format: any, lng: any) {
if (format === 'uppercase') return value.toUpperCase(); if (format === 'uppercase') return value.toUpperCase();
@ -157,11 +17,17 @@ function format(value: any, format: any, lng: any) {
i18n i18n
.init({ .init({
debug: true,
// load: 'languageOnly',
// initImmediate: false,
lng: getLanguage(),
fallbackLng: 'en', fallbackLng: 'en',
resources, resources,
interpolation: { interpolation: {
format: format format: format
}
}
}); });
export { i18n, resources }; export { i18n, resources };

124
ui/src/translations/de.ts Normal file
View file

@ -0,0 +1,124 @@
export const de = {
translation: {
post: 'post',
remove_post: 'Remove Post',
no_posts: 'No Posts.',
create_a_post: 'Create a post',
create_post: 'Create Post',
number_of_posts:'{{count}} Posts',
posts: 'Posts',
related_posts: 'These posts might be related',
comments: 'Comments',
number_of_comments:'{{count}} Comments',
remove_comment: 'Remove Comment',
communities: 'Communities',
create_a_community: 'Create a community',
create_community: 'Create Community',
remove_community: 'Remove Community',
subscribed_to_communities:'Subscribed to <1>communities</1>',
trending_communities:'Trending <1>communities</1>',
list_of_communities: 'List of communities',
community_reqs: 'lowercase, underscores, and no spaces.',
edit: 'edit',
reply: 'reply',
cancel: 'Cancel',
unlock: 'unlock',
lock: 'lock',
link: 'link',
mod: 'mod',
mods: 'mods',
moderates: 'Moderates',
remove_as_mod: 'remove as mod',
appoint_as_mod: 'appoint as mod',
modlog: 'Modlog',
admin: 'admin',
admins: 'admins',
remove_as_admin: 'remove as admin',
appoint_as_admin: 'appoint as admin',
remove: 'remove',
removed: 'removed',
locked: 'locked',
reason: 'Reason',
mark_as_read: 'mark as read',
mark_as_unread: 'mark as unread',
delete: 'delete',
deleted: 'deleted',
restore: 'restore',
ban: 'ban',
ban_from_site: 'ban from site',
unban: 'unban',
unban_from_site: 'unban from site',
save: 'save',
unsave: 'unsave',
create: 'create',
username: 'Username',
email_or_username: 'Email or Username',
number_of_users:'{{count}} Users',
number_of_subscribers:'{{count}} Subscribers',
number_of_points:'{{count}} Points',
name: 'Name',
title: 'Title',
category: 'Category',
subscribers: 'Subscribers',
both: 'Both',
saved: 'Saved',
unsubscribe: 'Unsubscribe',
subscribe: 'Subscribe',
prev: 'Prev',
next: 'Next',
sidebar: 'Sidebar',
sort_type: 'Sort type',
hot: 'Hot',
new: 'New',
top_day: 'Top day',
week: 'Week',
month: 'Month',
year: 'Year',
all: 'All',
top: 'Top',
api: 'API',
inbox: 'Inbox',
inbox_for: 'Inbox for <1>{{user}}</1>',
mark_all_as_read: 'mark all as read',
type: 'Type',
unread: 'Unread',
reply_sent: 'Reply sent',
search: 'Search',
overview: 'Overview',
view: 'View',
logout: 'Logout',
login_sign_up: 'Login / Sign up',
notifications_error: 'Desktop notifications not available in your browser. Try Firefox or Chrome.',
unread_messages: 'Unread Messages',
password: 'Password',
verify_password: 'Verify Password',
login: 'Login',
sign_up: 'Sign Up',
email: 'Email',
optional: 'Optional',
url: 'URL',
body: 'Body',
copy_suggested_title: 'copy suggested title: {{title}}',
community: 'Community',
expand_here: 'Expand here',
subscribe_to_communities: 'Subscribe to some <1>communities</1>.',
chat: 'Chat',
no_results: 'No results.',
setup: 'Setup',
lemmy_instance_setup: 'Lemmy Instance Setup',
setup_admin: 'Set Up Site Administrator',
your_site: 'your site',
modified: 'modified',
sponsors: 'Sponsors',
sponsors_of_lemmy: 'Sponsors of Lemmy',
sponsor_message: 'Lemmy is free, <1>open-source</1> software, meaning no advertising, monetizing, or venture capital, ever. Your donations directly support full-time development of the project. Thank you to the following people:',
support_on_patreon: 'Support on Patreon',
general_sponsors:'General Sponsors are those that pledged $10 to $39 to Lemmy.',
bitcoin: 'Bitcoin',
ethereum: 'Ethereum',
code: 'Code',
powered_by: 'Powered by',
landing_0: 'GERMAN Lemmy is a <1>link aggregator</1> / reddit alternative, intended to work in the <2>fediverse</2>.<3></3>Its self-hostable, has live-updating comment threads, and is tiny (<4>~80kB</4>). Federation into the ActivityPub network is on the roadmap. <5></5>This is a <6>very early beta version</6>, and a lot of features are currently broken or missing. <7></7>Suggest new features or report bugs <8>here.</8><9></9>Made with <10>Rust</10>, <11>Actix</11>, <12>Inferno</12>, <13>Typescript</13>.',
},
}

124
ui/src/translations/en.ts Normal file
View file

@ -0,0 +1,124 @@
export const en = {
translation: {
post: 'post',
remove_post: 'Remove Post',
no_posts: 'No Posts.',
create_a_post: 'Create a post',
create_post: 'Create Post',
number_of_posts:'{{count}} Posts',
posts: 'Posts',
related_posts: 'These posts might be related',
comments: 'Comments',
number_of_comments:'{{count}} Comments',
remove_comment: 'Remove Comment',
communities: 'Communities',
create_a_community: 'Create a community',
create_community: 'Create Community',
remove_community: 'Remove Community',
subscribed_to_communities:'Subscribed to <1>communities</1>',
trending_communities:'Trending <1>communities</1>',
list_of_communities: 'List of communities',
community_reqs: 'lowercase, underscores, and no spaces.',
edit: 'edit',
reply: 'reply',
cancel: 'Cancel',
unlock: 'unlock',
lock: 'lock',
link: 'link',
mod: 'mod',
mods: 'mods',
moderates: 'Moderates',
remove_as_mod: 'remove as mod',
appoint_as_mod: 'appoint as mod',
modlog: 'Modlog',
admin: 'admin',
admins: 'admins',
remove_as_admin: 'remove as admin',
appoint_as_admin: 'appoint as admin',
remove: 'remove',
removed: 'removed',
locked: 'locked',
reason: 'Reason',
mark_as_read: 'mark as read',
mark_as_unread: 'mark as unread',
delete: 'delete',
deleted: 'deleted',
restore: 'restore',
ban: 'ban',
ban_from_site: 'ban from site',
unban: 'unban',
unban_from_site: 'unban from site',
save: 'save',
unsave: 'unsave',
create: 'create',
username: 'Username',
email_or_username: 'Email or Username',
number_of_users:'{{count}} Users',
number_of_subscribers:'{{count}} Subscribers',
number_of_points:'{{count}} Points',
name: 'Name',
title: 'Title',
category: 'Category',
subscribers: 'Subscribers',
both: 'Both',
saved: 'Saved',
unsubscribe: 'Unsubscribe',
subscribe: 'Subscribe',
prev: 'Prev',
next: 'Next',
sidebar: 'Sidebar',
sort_type: 'Sort type',
hot: 'Hot',
new: 'New',
top_day: 'Top day',
week: 'Week',
month: 'Month',
year: 'Year',
all: 'All',
top: 'Top',
api: 'API',
inbox: 'Inbox',
inbox_for: 'Inbox for <1>{{user}}</1>',
mark_all_as_read: 'mark all as read',
type: 'Type',
unread: 'Unread',
reply_sent: 'Reply sent',
search: 'Search',
overview: 'Overview',
view: 'View',
logout: 'Logout',
login_sign_up: 'Login / Sign up',
notifications_error: 'Desktop notifications not available in your browser. Try Firefox or Chrome.',
unread_messages: 'Unread Messages',
password: 'Password',
verify_password: 'Verify Password',
login: 'Login',
sign_up: 'Sign Up',
email: 'Email',
optional: 'Optional',
url: 'URL',
body: 'Body',
copy_suggested_title: 'copy suggested title: {{title}}',
community: 'Community',
expand_here: 'Expand here',
subscribe_to_communities: 'Subscribe to some <1>communities</1>.',
chat: 'Chat',
no_results: 'No results.',
setup: 'Setup',
lemmy_instance_setup: 'Lemmy Instance Setup',
setup_admin: 'Set Up Site Administrator',
your_site: 'your site',
modified: 'modified',
sponsors: 'Sponsors',
sponsors_of_lemmy: 'Sponsors of Lemmy',
sponsor_message: 'Lemmy is free, <1>open-source</1> software, meaning no advertising, monetizing, or venture capital, ever. Your donations directly support full-time development of the project. Thank you to the following people:',
support_on_patreon: 'Support on Patreon',
general_sponsors:'General Sponsors are those that pledged $10 to $39 to Lemmy.',
bitcoin: 'Bitcoin',
ethereum: 'Ethereum',
code: 'Code',
powered_by: 'Powered by',
landing_0: 'Lemmy is a <1>link aggregator</1> / reddit alternative, intended to work in the <2>fediverse</2>.<3></3>Its self-hostable, has live-updating comment threads, and is tiny (<4>~80kB</4>). Federation into the ActivityPub network is on the roadmap. <5></5>This is a <6>very early beta version</6>, and a lot of features are currently broken or missing. <7></7>Suggest new features or report bugs <8>here.</8><9></9>Made with <10>Rust</10>, <11>Actix</11>, <12>Inferno</12>, <13>Typescript</13>.',
},
}

View file

@ -159,3 +159,7 @@ export function debounce(func: any, wait: number = 500, immediate: boolean = fal
if (callNow) func.apply(context, args); if (callNow) func.apply(context, args);
} }
} }
export function getLanguage() {
return (navigator.language || navigator.userLanguage);
}

View file

@ -2,7 +2,7 @@
# yarn lockfile v1 # yarn lockfile v1
"@babel/runtime@^7.1.2", "@babel/runtime@^7.3.1": "@babel/runtime@^7.1.2", "@babel/runtime@^7.3.1", "@babel/runtime@^7.5.5":
version "7.5.5" version "7.5.5"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.5.5.tgz#74fba56d35efbeca444091c7850ccd494fd2f132" resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.5.5.tgz#74fba56d35efbeca444091c7850ccd494fd2f132"
integrity sha512-28QvEGyQyNkB0/m2B4FU7IEZGK2NUrcMtT6BZEFALTguLk+AUT6ofsHtPk5QyjAdUkpMJ+/Em+quwz4HOt30AQ== integrity sha512-28QvEGyQyNkB0/m2B4FU7IEZGK2NUrcMtT6BZEFALTguLk+AUT6ofsHtPk5QyjAdUkpMJ+/Em+quwz4HOt30AQ==
@ -1212,6 +1212,18 @@ http-signature@~1.2.0:
jsprim "^1.2.2" jsprim "^1.2.2"
sshpk "^1.7.0" sshpk "^1.7.0"
i18next-browser-languagedetector@^3.0.3:
version "3.0.3"
resolved "https://registry.yarnpkg.com/i18next-browser-languagedetector/-/i18next-browser-languagedetector-3.0.3.tgz#879ebe421685c70cc5cfa96191364a35ea7da742"
integrity sha512-1YuAogyQap0J6N4kM+6gAjZ6T7QWrp3xZCmSs0QedkNmgAKhj7FiQlCviHKl3IwbM6zJNgft4D7UDPWb1dTCMQ==
i18next-xhr-backend@^3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/i18next-xhr-backend/-/i18next-xhr-backend-3.1.1.tgz#9221ba6911d466c38693fd43eb8ff10b48d3438a"
integrity sha512-Fui5puKb1pD+Z1+biwzA9jPQTvwOgz8SOkwu7yGRorCQraOgKxp86T310HoUM2CR9VV0MM2pJdntEQrgC45+RA==
dependencies:
"@babel/runtime" "^7.5.5"
i18next@^17.0.9: i18next@^17.0.9:
version "17.0.9" version "17.0.9"
resolved "https://registry.yarnpkg.com/i18next/-/i18next-17.0.9.tgz#5f835e91a34fa5e7da1e5ae4c4586c81d7c4b17f" resolved "https://registry.yarnpkg.com/i18next/-/i18next-17.0.9.tgz#5f835e91a34fa5e7da1e5ae4c4586c81d7c4b17f"