mirror of https://github.com/zulip/zulip.git
i18n: Remove i18next.
Fixes #17890. Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
2c3787196d
commit
d8a36d0702
|
@ -53,44 +53,3 @@ exports.$t_html = (descriptor, values) =>
|
|||
),
|
||||
},
|
||||
);
|
||||
|
||||
exports.i18n = {};
|
||||
exports.i18n.t = function (str, context) {
|
||||
// HAPPY PATH: most translations are a simple string:
|
||||
if (context === undefined) {
|
||||
return "translated: " + str;
|
||||
}
|
||||
|
||||
/*
|
||||
context will be an ordinary JS object like this:
|
||||
|
||||
{minutes: minutes.toString()}
|
||||
|
||||
This supports use cases like the following:
|
||||
|
||||
i18n.t("__minutes__ min to edit", {minutes: minutes.toString()})
|
||||
|
||||
We have to munge in the context here.
|
||||
*/
|
||||
const keyword_regex = /__(- )?(\w)+__/g;
|
||||
const keys_in_str = str.match(keyword_regex) || [];
|
||||
const substitutions = keys_in_str.map((key) => {
|
||||
let prefix_length;
|
||||
if (key.startsWith("__- ")) {
|
||||
prefix_length = 4;
|
||||
} else {
|
||||
prefix_length = 2;
|
||||
}
|
||||
return {
|
||||
keyword: key.slice(prefix_length, -2),
|
||||
prefix: key.slice(0, prefix_length),
|
||||
suffix: key.slice(-2, key.length),
|
||||
};
|
||||
});
|
||||
|
||||
for (const item of substitutions) {
|
||||
str = str.replace(item.prefix + item.keyword + item.suffix, context[item.keyword]);
|
||||
}
|
||||
|
||||
return "translated: " + str;
|
||||
};
|
||||
|
|
|
@ -46,7 +46,6 @@
|
|||
"handlebars": "^4.7.2",
|
||||
"handlebars-loader": "^1.7.1",
|
||||
"html-webpack-plugin": "^4.0.0-beta.8",
|
||||
"i18next": "^20.2.1",
|
||||
"jquery": "^3.4.1",
|
||||
"jquery-caret-plugin": "^1.5.2",
|
||||
"jquery-validation": "^1.19.0",
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
// https://zulip.readthedocs.io/en/latest/translating/internationalization.html
|
||||
|
||||
import {createIntl, createIntlCache} from "@formatjs/intl";
|
||||
import i18next from "i18next";
|
||||
import _ from "lodash";
|
||||
|
||||
import {page_params} from "./page_params";
|
||||
|
@ -37,21 +36,3 @@ export function $t_html(descriptor, values) {
|
|||
),
|
||||
});
|
||||
}
|
||||
|
||||
i18next.init({
|
||||
lng: "lang",
|
||||
resources: {
|
||||
lang: {
|
||||
translation: page_params.translation_data,
|
||||
},
|
||||
},
|
||||
nsSeparator: false,
|
||||
keySeparator: false,
|
||||
interpolation: {
|
||||
prefix: "__",
|
||||
suffix: "__",
|
||||
},
|
||||
returnEmptyString: false, // Empty string is not a valid translation.
|
||||
});
|
||||
|
||||
export const i18n = i18next;
|
||||
|
|
|
@ -45,4 +45,4 @@ API_FEATURE_LEVEL = 54
|
|||
# historical commits sharing the same major version, in which case a
|
||||
# minor version bump suffices.
|
||||
|
||||
PROVISION_VERSION = "139.2"
|
||||
PROVISION_VERSION = "140.0"
|
||||
|
|
|
@ -891,7 +891,7 @@
|
|||
pirates "^4.0.0"
|
||||
source-map-support "^0.5.16"
|
||||
|
||||
"@babel/runtime@^7.12.0", "@babel/runtime@^7.12.5", "@babel/runtime@^7.7.2", "@babel/runtime@^7.8.4":
|
||||
"@babel/runtime@^7.12.5", "@babel/runtime@^7.7.2", "@babel/runtime@^7.8.4":
|
||||
version "7.13.10"
|
||||
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.13.10.tgz#47d42a57b6095f4468da440388fdbad8bebf0d7d"
|
||||
integrity sha512-4QPkjJq6Ns3V/RgpEahRk+AGfL0eO6RHHtTWoNNr5mO49G6B5+X6d6THgWEAvTrznU5xYpbAlVKRYcsCgh/Akw==
|
||||
|
@ -7119,13 +7119,6 @@ human-signals@^2.1.0:
|
|||
resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-2.1.0.tgz#dc91fcba42e4d06e4abaed33b3e7a3c02f514ea0"
|
||||
integrity sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==
|
||||
|
||||
i18next@^20.2.1:
|
||||
version "20.2.1"
|
||||
resolved "https://registry.yarnpkg.com/i18next/-/i18next-20.2.1.tgz#8aedfdc596f7d54b9d3f6d87bcb89214467cb785"
|
||||
integrity sha512-JLruWDEQ3T6tKT6P7u+DsNtToMHUwUcQIYOMRcnNBdUhSfKkoIDUKdVDKgGtmqr//LrirxjADUdr3d5Gwbow6g==
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.12.0"
|
||||
|
||||
iconv-lite@0.4.24:
|
||||
version "0.4.24"
|
||||
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b"
|
||||
|
|
|
@ -58,10 +58,6 @@ regexes = [
|
|||
r'\(t "(.*?)"\)',
|
||||
r'=\(t "(.*?)"\)(?=[^{]*}})',
|
||||
r"=\(t '(.*?)'\)(?=[^{]*}})",
|
||||
r"i18n\.t\('([^']*?)'\)",
|
||||
r"i18n\.t\('(.*?)',\s*.*?[^,]\)",
|
||||
r'i18n\.t\("([^"]*?)"\)',
|
||||
r'i18n\.t\("(.*?)",\s*.*?[^,]\)',
|
||||
]
|
||||
tags = [
|
||||
("err_", "error"),
|
||||
|
|
|
@ -166,10 +166,6 @@ class FrontendRegexTestCase(ZulipTestCase):
|
|||
('{{t "english text" }}, "extra"}}', "english text"),
|
||||
("{{t 'english text' }}, 'extra'}}", "english text"),
|
||||
("{{> template var=(t 'english text') }}, 'extra'}}", "english text"),
|
||||
('i18n.t("english text"), "extra",)', "english text"),
|
||||
('i18n.t("english text", context), "extra",)', "english text"),
|
||||
("i18n.t('english text'), 'extra',)", "english text"),
|
||||
("i18n.t('english text', context), 'extra',)", "english text"),
|
||||
]
|
||||
|
||||
for input_text, expected in data:
|
||||
|
|
Loading…
Reference in New Issue