aboutsummaryrefslogtreecommitdiff
path: root/src/webex/i18n.tsx
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2020-03-30 16:09:32 +0530
committerFlorian Dold <florian.dold@gmail.com>2020-03-30 16:09:32 +0530
commitaaf950e2ad5c07d4423f9822e3a0ae9f7b8d2bdf (patch)
tree9274139660f30c4857d80044eb4ac283aac1775a /src/webex/i18n.tsx
parent15e18440dbad55df19977a2eb7053681259afc18 (diff)
downloadwallet-core-aaf950e2ad5c07d4423f9822e3a0ae9f7b8d2bdf.tar.xz
re-format with prettier v2, fix HTML
Diffstat (limited to 'src/webex/i18n.tsx')
-rw-r--r--src/webex/i18n.tsx75
1 files changed, 49 insertions, 26 deletions
diff --git a/src/webex/i18n.tsx b/src/webex/i18n.tsx
index 3923654e7..2e753e441 100644
--- a/src/webex/i18n.tsx
+++ b/src/webex/i18n.tsx
@@ -21,19 +21,17 @@
/**
* Imports.
*/
-import {strings} from "../i18n/strings";
+import { strings } from "../i18n/strings";
// @ts-ignore: no type decl for this library
import * as jedLib from "jed";
import * as React from "react";
-
const jed = setupJed();
let enableTracing = false;
-
/**
* Set up jed library for internationalization,
* based on browser language settings.
@@ -56,7 +54,6 @@ function setupJed(): any {
return new jedLib.Jed(strings[lang]);
}
-
/**
* Convert template strings to a msgid
*/
@@ -71,22 +68,22 @@ function toI18nString(stringSeq: ReadonlyArray<string>) {
return s;
}
-
/**
* Internationalize a string template with arbitrary serialized values.
*/
export function str(stringSeq: TemplateStringsArray, ...values: any[]) {
const s = toI18nString(stringSeq);
- const tr = jed.translate(s).ifPlural(1, s).fetch(...values);
+ const tr = jed
+ .translate(s)
+ .ifPlural(1, s)
+ .fetch(...values);
return tr;
}
-
interface TranslateSwitchProps {
target: number;
}
-
function stringifyChildren(children: any): string {
let n = 1;
const ss = React.Children.map(children, (c) => {
@@ -100,7 +97,6 @@ function stringifyChildren(children: any): string {
return s;
}
-
interface TranslateProps {
/**
* Component that the translated element should be wrapped in.
@@ -114,7 +110,6 @@ interface TranslateProps {
wrapProps?: any;
}
-
/**
* Translate text node children of this component.
* If a child component might produce a text node, it must be wrapped
@@ -130,11 +125,19 @@ interface TranslateProps {
export class Translate extends React.Component<TranslateProps, {}> {
render(): JSX.Element {
const s = stringifyChildren(this.props.children);
- const tr = jed.ngettext(s, s, 1).split(/%(\d+)\$s/).filter((e: any, i: number) => i % 2 === 0);
+ const tr = jed
+ .ngettext(s, s, 1)
+ .split(/%(\d+)\$s/)
+ .filter((e: any, i: number) => i % 2 === 0);
const childArray = React.Children.toArray(this.props.children!);
for (let i = 0; i < childArray.length - 1; ++i) {
- if ((typeof childArray[i]) === "string" && (typeof childArray[i + 1]) === "string") {
- childArray[i + 1] = (childArray[i] as string).concat(childArray[i + 1] as string);
+ if (
+ typeof childArray[i] === "string" &&
+ typeof childArray[i + 1] === "string"
+ ) {
+ childArray[i + 1] = (childArray[i] as string).concat(
+ childArray[i + 1] as string,
+ );
childArray.splice(i, 1);
}
}
@@ -158,7 +161,6 @@ export class Translate extends React.Component<TranslateProps, {}> {
}
}
-
/**
* Switch translation based on singular or plural based on the target prop.
* Should only contain TranslateSingular and TransplatePlural as children.
@@ -171,7 +173,10 @@ export class Translate extends React.Component<TranslateProps, {}> {
* </TranslateSwitch>
* ```
*/
-export class TranslateSwitch extends React.Component<TranslateSwitchProps, void> {
+export class TranslateSwitch extends React.Component<
+ TranslateSwitchProps,
+ void
+> {
render(): JSX.Element {
let singular: React.ReactElement<TranslationPluralProps> | undefined;
let plural: React.ReactElement<TranslationPluralProps> | undefined;
@@ -186,7 +191,7 @@ export class TranslateSwitch extends React.Component<TranslateSwitchProps, void>
}
});
}
- if ((!singular) || (!plural)) {
+ if (!singular || !plural) {
console.error("translation not found");
return React.createElement("span", {}, ["translation not found"]);
}
@@ -198,7 +203,6 @@ export class TranslateSwitch extends React.Component<TranslateSwitchProps, void>
}
}
-
interface TranslationPluralProps {
target: number;
}
@@ -206,14 +210,24 @@ interface TranslationPluralProps {
/**
* See [[TranslateSwitch]].
*/
-export class TranslatePlural extends React.Component<TranslationPluralProps, void> {
+export class TranslatePlural extends React.Component<
+ TranslationPluralProps,
+ void
+> {
render(): JSX.Element {
const s = stringifyChildren(this.props.children);
- const tr = jed.ngettext(s, s, 1).split(/%(\d+)\$s/).filter((e: any, i: number) => i % 2 === 0);
+ const tr = jed
+ .ngettext(s, s, 1)
+ .split(/%(\d+)\$s/)
+ .filter((e: any, i: number) => i % 2 === 0);
const childArray = React.Children.toArray(this.props.children!);
for (let i = 0; i < childArray.length - 1; ++i) {
- if ((typeof childArray[i]) === "string" && (typeof childArray[i + 1]) === "string") {
- childArray[i + i] = childArray[i] as string + childArray[i + 1] as string;
+ if (
+ typeof childArray[i] === "string" &&
+ typeof childArray[i + 1] === "string"
+ ) {
+ childArray[i + i] = ((childArray[i] as string) +
+ childArray[i + 1]) as string;
childArray.splice(i, 1);
}
}
@@ -234,18 +248,27 @@ export class TranslatePlural extends React.Component<TranslationPluralProps, voi
}
}
-
/**
* See [[TranslateSwitch]].
*/
-export class TranslateSingular extends React.Component<TranslationPluralProps, void> {
+export class TranslateSingular extends React.Component<
+ TranslationPluralProps,
+ void
+> {
render(): JSX.Element {
const s = stringifyChildren(this.props.children);
- const tr = jed.ngettext(s, s, 1).split(/%(\d+)\$s/).filter((e: any, i: number) => i % 2 === 0);
+ const tr = jed
+ .ngettext(s, s, 1)
+ .split(/%(\d+)\$s/)
+ .filter((e: any, i: number) => i % 2 === 0);
const childArray = React.Children.toArray(this.props.children!);
for (let i = 0; i < childArray.length - 1; ++i) {
- if ((typeof childArray[i]) === "string" && (typeof childArray[i + 1]) === "string") {
- childArray[i + i] = childArray[i] as string + childArray[i + 1] as string;
+ if (
+ typeof childArray[i] === "string" &&
+ typeof childArray[i + 1] === "string"
+ ) {
+ childArray[i + i] = ((childArray[i] as string) +
+ childArray[i + 1]) as string;
childArray.splice(i, 1);
}
}