Skip to content
This repository has been archived by the owner on Dec 10, 2021. It is now read-only.

Commit

Permalink
Move files
Browse files Browse the repository at this point in the history
  • Loading branch information
ktmud committed Aug 4, 2020
1 parent b5ced07 commit f254ef6
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 46 deletions.
25 changes: 22 additions & 3 deletions packages/superset-ui-translation/src/Translator.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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;
}

Expand Down
8 changes: 6 additions & 2 deletions packages/superset-ui-translation/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -42,6 +42,10 @@ export type LanguagePack = JedOptions & {
};
};

export interface Jed extends BaseJed {
options: LanguagePack;
}

/**
* Config options for Translator class.
*/
Expand Down
41 changes: 0 additions & 41 deletions packages/superset-ui-translation/src/types/jed.d.ts

This file was deleted.

35 changes: 35 additions & 0 deletions packages/superset-ui-translation/src/types/jed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Translations for a language in the format of { key: [singular, plural, ...]}.
*/
export type Translations = {
[key: string]: ReadonlyArray<string>;
};

export interface DomainConfig {
domain: string;
lang: string;
// eslint-disable-next-line camelcase
plural_forms: string;
}

export type DomainData = { '': DomainConfig } & {
[key: string]: ReadonlyArray<string> | 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;
}
1 change: 1 addition & 0 deletions packages/superset-ui-translation/types/external.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module 'jed';

0 comments on commit f254ef6

Please sign in to comment.