From: Dessalines Date: Fri, 9 Aug 2019 05:09:36 +0000 (-0700) Subject: Localization testing mostly done. X-Git-Url: http://these/git/%22https:/github.com/LemmyNet/lemmy/issues/README.es.md?a=commitdiff_plain;h=91a3d1439381e25955f84f70fd9ebb21fc6160ba;p=lemmy.git Localization testing mostly done. --- diff --git a/ui/package.json b/ui/package.json index 180d80ef..d86725f2 100644 --- a/ui/package.json +++ b/ui/package.json @@ -23,10 +23,10 @@ "autosize": "^4.0.2", "classcat": "^1.1.3", "dotenv": "^6.1.0", - "inferno": "^7.0.1", - "inferno-router": "^7.0.1", "i18next": "^17.0.9", + "inferno": "^7.0.1", "inferno-i18next": "nimbusec-oss/inferno-i18next", + "inferno-router": "^7.0.1", "js-cookie": "^2.2.0", "jwt-decode": "^2.2.0", "markdown-it": "^8.4.2", diff --git a/ui/src/components/moment-time.tsx b/ui/src/components/moment-time.tsx index c6c7c99d..b35ceea8 100644 --- a/ui/src/components/moment-time.tsx +++ b/ui/src/components/moment-time.tsx @@ -1,5 +1,7 @@ import { Component } from 'inferno'; import * as moment from 'moment'; +import 'moment/locale/de.js'; +import { getLanguage } from '../utils'; import { i18n } from '../i18next'; interface MomentTimeProps { @@ -14,6 +16,8 @@ export class MomentTime extends Component { constructor(props: any, context: any) { super(props, context); + // console.log(moment.locales()); + moment.locale(getLanguage()); } render() { diff --git a/ui/src/i18next.ts b/ui/src/i18next.ts index 816c4c07..3b2ad604 100644 --- a/ui/src/i18next.ts +++ b/ui/src/i18next.ts @@ -1,154 +1,14 @@ 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 -// // TODO don't forget to add moment locales for new languages. const resources = { - en: { - translation: { - 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', - 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', - 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 / reddit alternative, intended to work in the <2>fediverse.<3>Its self-hostable, has live-updating comment threads, and is tiny (<4>~80kB). Federation into the ActivityPub network is on the roadmap. <5>This is a <6>very early beta version, and a lot of features are currently broken or missing. <7>Suggest new features or report bugs <8>here.<9>Made with <10>Rust, <11>Actix, <12>Inferno, <13>Typescript.', - 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 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}}', - 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.', - - 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', - baz: '<1>{{count}}', - qux: 'qux<1>', - qux_plural: 'quxes<1>', - quux: '<1>{{name, uppercase}}', - userMessagesUnread: 'Hello <1>{{name}}, you have {{count}} unread messages. <3>Go to messages.', - userMessagesUnread_plural: 'Hello <1>{{name}}, you have {{count}} unread messages. <3>Go to messages.' - }, - }, -}; + en: en, + de: de, +} function format(value: any, format: any, lng: any) { if (format === 'uppercase') return value.toUpperCase(); @@ -157,11 +17,17 @@ function format(value: any, format: any, lng: any) { i18n .init({ + debug: true, + // load: 'languageOnly', + + // initImmediate: false, + lng: getLanguage(), fallbackLng: 'en', resources, interpolation: { - format: format - } + format: format + + } }); export { i18n, resources }; diff --git a/ui/src/translations/de.ts b/ui/src/translations/de.ts new file mode 100644 index 00000000..543d74dc --- /dev/null +++ b/ui/src/translations/de.ts @@ -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', + trending_communities:'Trending <1>communities', + 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}}', + 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.', + 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 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 / reddit alternative, intended to work in the <2>fediverse.<3>Its self-hostable, has live-updating comment threads, and is tiny (<4>~80kB). Federation into the ActivityPub network is on the roadmap. <5>This is a <6>very early beta version, and a lot of features are currently broken or missing. <7>Suggest new features or report bugs <8>here.<9>Made with <10>Rust, <11>Actix, <12>Inferno, <13>Typescript.', + }, +} + diff --git a/ui/src/translations/en.ts b/ui/src/translations/en.ts new file mode 100644 index 00000000..bc0274cd --- /dev/null +++ b/ui/src/translations/en.ts @@ -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', + trending_communities:'Trending <1>communities', + 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}}', + 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.', + 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 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 / reddit alternative, intended to work in the <2>fediverse.<3>Its self-hostable, has live-updating comment threads, and is tiny (<4>~80kB). Federation into the ActivityPub network is on the roadmap. <5>This is a <6>very early beta version, and a lot of features are currently broken or missing. <7>Suggest new features or report bugs <8>here.<9>Made with <10>Rust, <11>Actix, <12>Inferno, <13>Typescript.', + }, +} + diff --git a/ui/src/utils.ts b/ui/src/utils.ts index b9d9a389..c48b00c6 100644 --- a/ui/src/utils.ts +++ b/ui/src/utils.ts @@ -159,3 +159,7 @@ export function debounce(func: any, wait: number = 500, immediate: boolean = fal if (callNow) func.apply(context, args); } } + +export function getLanguage() { + return (navigator.language || navigator.userLanguage); +} diff --git a/ui/yarn.lock b/ui/yarn.lock index f47c16c4..578136b0 100644 --- a/ui/yarn.lock +++ b/ui/yarn.lock @@ -2,7 +2,7 @@ # 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" resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.5.5.tgz#74fba56d35efbeca444091c7850ccd494fd2f132" integrity sha512-28QvEGyQyNkB0/m2B4FU7IEZGK2NUrcMtT6BZEFALTguLk+AUT6ofsHtPk5QyjAdUkpMJ+/Em+quwz4HOt30AQ== @@ -1212,6 +1212,18 @@ http-signature@~1.2.0: jsprim "^1.2.2" 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: version "17.0.9" resolved "https://registry.yarnpkg.com/i18next/-/i18next-17.0.9.tgz#5f835e91a34fa5e7da1e5ae4c4586c81d7c4b17f"