From f254ef6f13202565662623f1e5abf4bae42b79ca Mon Sep 17 00:00:00 2001 From: Jesse Yang Date: Tue, 4 Aug 2020 13:02:16 -0700 Subject: [PATCH] Move files --- .../superset-ui-translation/src/Translator.ts | 25 +++++++++-- .../src/types/index.ts | 8 +++- .../src/types/jed.d.ts | 41 ------------------- .../superset-ui-translation/src/types/jed.ts | 35 ++++++++++++++++ .../types/external.d.ts | 1 + 5 files changed, 64 insertions(+), 46 deletions(-) delete mode 100644 packages/superset-ui-translation/src/types/jed.d.ts create mode 100644 packages/superset-ui-translation/src/types/jed.ts create mode 100644 packages/superset-ui-translation/types/external.d.ts diff --git a/packages/superset-ui-translation/src/Translator.ts b/packages/superset-ui-translation/src/Translator.ts index 11e82c114b..d73789b3bd 100644 --- a/packages/superset-ui-translation/src/Translator.ts +++ b/packages/superset-ui-translation/src/Translator.ts @@ -1,6 +1,24 @@ -import Jed from 'jed'; +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import UntyppedJed from 'jed'; import { logging } from '@superset-ui/core'; -import { TranslatorConfig, Locale, Translations, LocaleData, LanguagePack } from './types'; +import { Jed, TranslatorConfig, Locale, Translations, LocaleData, LanguagePack } from './types'; const DEFAULT_LANGUAGE_PACK: LanguagePack = { domain: 'superset', @@ -22,7 +40,8 @@ export default class Translator { constructor(config: TranslatorConfig = {}) { const { languagePack = DEFAULT_LANGUAGE_PACK } = config; - this.i18n = new Jed(languagePack); + // eslint-disable-next-line @typescript-eslint/no-unsafe-call + this.i18n = new UntyppedJed(languagePack) as Jed; this.locale = this.i18n.options.locale_data.superset[''].lang as Locale; } diff --git a/packages/superset-ui-translation/src/types/index.ts b/packages/superset-ui-translation/src/types/index.ts index 0d03a1121c..f641ec8fab 100644 --- a/packages/superset-ui-translation/src/types/index.ts +++ b/packages/superset-ui-translation/src/types/index.ts @@ -16,9 +16,9 @@ * specific language governing permissions and limitations * under the License. */ -import { JedOptions, DomainData, Translations } from 'jed'; +import { Jed as BaseJed, JedOptions, DomainData, Translations } from './jed'; -export { Translations } from 'jed'; +export { Translations } from './jed'; /** * Superset supported languages. @@ -42,6 +42,10 @@ export type LanguagePack = JedOptions & { }; }; +export interface Jed extends BaseJed { + options: LanguagePack; +} + /** * Config options for Translator class. */ diff --git a/packages/superset-ui-translation/src/types/jed.d.ts b/packages/superset-ui-translation/src/types/jed.d.ts deleted file mode 100644 index 49e62071c9..0000000000 --- a/packages/superset-ui-translation/src/types/jed.d.ts +++ /dev/null @@ -1,41 +0,0 @@ -declare module 'jed' { - /** - * Translations for a language in the format of { key: [singular, plural, ...]}. - */ - export type Translations = { - [key: string]: ReadonlyArray; - }; - - type x = Translations['']; - - export interface DomainConfig { - domain: string; - lang: string; - // eslint-disable-next-line camelcase - plural_forms: string; - } - - export type DomainData = { '': DomainConfig } & { - [key: string]: ReadonlyArray | DomainConfig; - }; - - export interface JedOptions { - domain: string; - // eslint-disable-next-line camelcase - locale_data: { - [domain: string]: DomainData; - }; - } - - export default class Jed { - constructor(options: JedOptions); - - translate(input: string): Jed; - - ifPlural(value: number, plural: string): Jed; - - fetch(...args: unknown[]): string; - - options: JedOptions; - } -} diff --git a/packages/superset-ui-translation/src/types/jed.ts b/packages/superset-ui-translation/src/types/jed.ts new file mode 100644 index 0000000000..1353c403ae --- /dev/null +++ b/packages/superset-ui-translation/src/types/jed.ts @@ -0,0 +1,35 @@ +/** + * Translations for a language in the format of { key: [singular, plural, ...]}. + */ +export type Translations = { + [key: string]: ReadonlyArray; +}; + +export interface DomainConfig { + domain: string; + lang: string; + // eslint-disable-next-line camelcase + plural_forms: string; +} + +export type DomainData = { '': DomainConfig } & { + [key: string]: ReadonlyArray | DomainConfig; +}; + +export interface JedOptions { + domain: string; + // eslint-disable-next-line camelcase + locale_data: { + [domain: string]: DomainData; + }; +} + +export interface Jed { + translate(input: string): Jed; + + ifPlural(value: number, plural: string): Jed; + + fetch(...args: unknown[]): string; + + options: JedOptions; +} diff --git a/packages/superset-ui-translation/types/external.d.ts b/packages/superset-ui-translation/types/external.d.ts new file mode 100644 index 0000000000..1175c8147a --- /dev/null +++ b/packages/superset-ui-translation/types/external.d.ts @@ -0,0 +1 @@ +declare module 'jed';