Skip to content

Commit

Permalink
version increment (#36)
Browse files Browse the repository at this point in the history
* version increment

* refactored data types
  • Loading branch information
yevheniyJ committed Feb 12, 2022
1 parent 08b07b6 commit 4c8b4f6
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 149 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@crowdin/ota-client",
"version": "0.6.0",
"version": "0.7.0",
"description": "JavaScript library for Crowdin OTA Content Delivery",
"main": "out/index.js",
"types": "out/index.d.ts",
Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export default class OtaClient {
private stringsCache: { [file: string]: { [language: string]: Promise<any> } } = {};
private disableStringsCache = false;

private languagesCache: Promise<APIData> | null = null;
private languagesCache: Promise<Language[]> | null = null;
private disableLanguagesCache = false;
private enterpriseOrganizationDomain: string | null = null;

Expand Down Expand Up @@ -422,19 +422,19 @@ export default class OtaClient {
return (await this.listFiles()).filter(f => !file || file === f).filter(isJsonFile);
}

private getLanguages(): Promise<APIData> {
private getLanguages(): Promise<Language[]> {
if (this.languagesCache) {
return this.languagesCache;
}
const languages = this.httpClient.get<APIData>(this.apiURL);
const languages = this.httpClient.get<LanguagesData>(this.apiURL).then(d => d.data.map(l => l.data));
if (!this.disableLanguagesCache) {
this.languagesCache = languages;
}
return languages;
}
}

export interface APIData {
interface LanguagesData {
data: {
data: Language;
}[];
Expand Down
9 changes: 4 additions & 5 deletions src/internal/util/exportPattern.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { APIData, CustomLanguageRaw, LanguageMapping } from '../..';
import { CustomLanguageRaw, LanguageMapping } from '../..';

export interface Language {
id: string;
Expand Down Expand Up @@ -59,10 +59,9 @@ export function includesLanguagePlaceholders(str: string): boolean {

export function findLanguageObject(
languageCode: string,
apiLanguages: APIData,
languages: Language[],
customLanguage?: CustomLanguageRaw,
): CustomLanguage {
const languages = apiLanguages.data.map(l => l.data);
let language: CustomLanguage | undefined;
if (customLanguage) {
language = {
Expand All @@ -87,11 +86,11 @@ export function findLanguageObject(
export function replaceLanguagePlaceholders(
str: string,
languageCode: string,
apiLanguages: APIData,
languages: Language[],
languageMapping?: LanguageMapping,
customLanguage?: CustomLanguageRaw,
): string {
const language = findLanguageObject(languageCode, apiLanguages, customLanguage);
const language = findLanguageObject(languageCode, languages, customLanguage);
let result = str;
for (const placeholder of Object.keys(languagePlaceholders)) {
if (result.includes(placeholder)) {
Expand Down
264 changes: 126 additions & 138 deletions tests/internal/util/exportPattern.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { APIData, CustomLanguageRaw } from '../../../src';
import { includesLanguagePlaceholders, replaceLanguagePlaceholders } from '../../../src/internal/util/exportPattern';
import { CustomLanguageRaw } from '../../../src';
import {
includesLanguagePlaceholders,
Language,
replaceLanguagePlaceholders,
} from '../../../src/internal/util/exportPattern';

describe('Export Pattern Util', () => {
it('should detect language placehodlers', () => {
Expand All @@ -9,142 +13,126 @@ describe('Export Pattern Util', () => {
expect(includesLanguagePlaceholders(string2)).toBe(false);
});

const languages: APIData = {
data: [
{
data: {
id: 'uk',
name: 'Ukrainian',
editorCode: 'uk',
twoLettersCode: 'uk',
threeLettersCode: 'ukr',
locale: 'uk-UA',
androidCode: 'uk-rUA',
osxCode: 'uk.lproj',
osxLocale: 'uk',
pluralCategoryNames: ['one', 'few', 'many', 'other'],
pluralRules:
'((n%10==1 && n%100!=11) ? 0 : ((n%10 >= 2 && n%10 <=4 && (n%100 < 12 || n%100 > 14)) ? 1 : ((n%10 == 0 || (n%10 >= 5 && n%10 <=9)) || (n%100 >= 11 && n%100 <= 14)) ? 2 : 3))',
pluralExamples: [
'1, 21, 31, 41, 51, 61, 71, 81...',
'2-4, 22-24, 32-34, 42-44, 52-54, 62...',
'0, 5-19, 100, 1000, 10000...',
'0.0-0.9, 1.1-1.6, 10.0, 100.0...',
],
textDirection: 'ltr',
dialectOf: null,
},
},
{
data: {
id: 'es-ES',
name: 'Spanish',
editorCode: 'es',
twoLettersCode: 'es',
threeLettersCode: 'spa',
locale: 'es-ES',
androidCode: 'es-rES',
osxCode: 'es.lproj',
osxLocale: 'es',
pluralCategoryNames: ['one', 'other'],
pluralRules: '(n != 1)',
pluralExamples: ['1', '0, 2-999; 1.2, 2.07...'],
textDirection: 'ltr',
dialectOf: null,
},
},
{
data: {
id: 'en',
name: 'English',
editorCode: 'en',
twoLettersCode: 'en',
threeLettersCode: 'eng',
locale: 'en-US',
androidCode: 'en-rUS',
osxCode: 'en.lproj',
osxLocale: 'en',
pluralCategoryNames: ['one', 'other'],
pluralRules: '(n != 1)',
pluralExamples: ['1', '0, 2-999; 1.2, 2.07...'],
textDirection: 'ltr',
dialectOf: null,
},
},
{
data: {
id: 'de',
name: 'German',
editorCode: 'de',
twoLettersCode: 'de',
threeLettersCode: 'deu',
locale: 'de-DE',
androidCode: 'de-rDE',
osxCode: 'de.lproj',
osxLocale: 'de',
pluralCategoryNames: ['one', 'other'],
pluralRules: '(n != 1)',
pluralExamples: ['1', '0, 2-999; 1.2, 2.07...'],
textDirection: 'ltr',
dialectOf: null,
},
},
{
data: {
id: 'es-US',
name: 'Spanish, United States',
editorCode: 'esus',
twoLettersCode: 'es',
threeLettersCode: 'spa',
locale: 'es-US',
androidCode: 'es-rUS',
osxCode: 'es-US.lproj',
osxLocale: 'es_US',
pluralCategoryNames: ['one', 'other'],
pluralRules: '(n != 1)',
pluralExamples: ['1', '0, 2-999; 1.2, 2.07...'],
textDirection: 'ltr',
dialectOf: 'es-ES',
},
},
{
data: {
id: 'en-GB',
name: 'English, United Kingdom',
editorCode: 'engb',
twoLettersCode: 'en',
threeLettersCode: 'eng',
locale: 'en-GB',
androidCode: 'en-rGB',
osxCode: 'en-GB.lproj',
osxLocale: 'en_GB',
pluralCategoryNames: ['one', 'other'],
pluralRules: '(n != 1)',
pluralExamples: ['1', '0, 2-999; 1.2, 2.07...'],
textDirection: 'ltr',
dialectOf: 'en',
},
},
{
data: {
id: 'pt-PT',
name: 'Portuguese',
editorCode: 'pt',
twoLettersCode: 'pt',
threeLettersCode: 'por',
locale: 'pt-PT',
androidCode: 'pt-rPT',
osxCode: 'pt.lproj',
osxLocale: 'pt',
pluralCategoryNames: ['one', 'other'],
pluralRules: '(n != 1)',
pluralExamples: ['1', '0, 2-999; 1.2, 2.07...'],
textDirection: 'ltr',
dialectOf: null,
},
},
],
};
const languages: Language[] = [
{
id: 'uk',
name: 'Ukrainian',
editorCode: 'uk',
twoLettersCode: 'uk',
threeLettersCode: 'ukr',
locale: 'uk-UA',
androidCode: 'uk-rUA',
osxCode: 'uk.lproj',
osxLocale: 'uk',
pluralCategoryNames: ['one', 'few', 'many', 'other'],
pluralRules:
'((n%10==1 && n%100!=11) ? 0 : ((n%10 >= 2 && n%10 <=4 && (n%100 < 12 || n%100 > 14)) ? 1 : ((n%10 == 0 || (n%10 >= 5 && n%10 <=9)) || (n%100 >= 11 && n%100 <= 14)) ? 2 : 3))',
pluralExamples: [
'1, 21, 31, 41, 51, 61, 71, 81...',
'2-4, 22-24, 32-34, 42-44, 52-54, 62...',
'0, 5-19, 100, 1000, 10000...',
'0.0-0.9, 1.1-1.6, 10.0, 100.0...',
],
textDirection: 'ltr',
dialectOf: null,
},
{
id: 'es-ES',
name: 'Spanish',
editorCode: 'es',
twoLettersCode: 'es',
threeLettersCode: 'spa',
locale: 'es-ES',
androidCode: 'es-rES',
osxCode: 'es.lproj',
osxLocale: 'es',
pluralCategoryNames: ['one', 'other'],
pluralRules: '(n != 1)',
pluralExamples: ['1', '0, 2-999; 1.2, 2.07...'],
textDirection: 'ltr',
dialectOf: null,
},
{
id: 'en',
name: 'English',
editorCode: 'en',
twoLettersCode: 'en',
threeLettersCode: 'eng',
locale: 'en-US',
androidCode: 'en-rUS',
osxCode: 'en.lproj',
osxLocale: 'en',
pluralCategoryNames: ['one', 'other'],
pluralRules: '(n != 1)',
pluralExamples: ['1', '0, 2-999; 1.2, 2.07...'],
textDirection: 'ltr',
dialectOf: null,
},
{
id: 'de',
name: 'German',
editorCode: 'de',
twoLettersCode: 'de',
threeLettersCode: 'deu',
locale: 'de-DE',
androidCode: 'de-rDE',
osxCode: 'de.lproj',
osxLocale: 'de',
pluralCategoryNames: ['one', 'other'],
pluralRules: '(n != 1)',
pluralExamples: ['1', '0, 2-999; 1.2, 2.07...'],
textDirection: 'ltr',
dialectOf: null,
},
{
id: 'es-US',
name: 'Spanish, United States',
editorCode: 'esus',
twoLettersCode: 'es',
threeLettersCode: 'spa',
locale: 'es-US',
androidCode: 'es-rUS',
osxCode: 'es-US.lproj',
osxLocale: 'es_US',
pluralCategoryNames: ['one', 'other'],
pluralRules: '(n != 1)',
pluralExamples: ['1', '0, 2-999; 1.2, 2.07...'],
textDirection: 'ltr',
dialectOf: 'es-ES',
},
{
id: 'en-GB',
name: 'English, United Kingdom',
editorCode: 'engb',
twoLettersCode: 'en',
threeLettersCode: 'eng',
locale: 'en-GB',
androidCode: 'en-rGB',
osxCode: 'en-GB.lproj',
osxLocale: 'en_GB',
pluralCategoryNames: ['one', 'other'],
pluralRules: '(n != 1)',
pluralExamples: ['1', '0, 2-999; 1.2, 2.07...'],
textDirection: 'ltr',
dialectOf: 'en',
},
{
id: 'pt-PT',
name: 'Portuguese',
editorCode: 'pt',
twoLettersCode: 'pt',
threeLettersCode: 'por',
locale: 'pt-PT',
androidCode: 'pt-rPT',
osxCode: 'pt.lproj',
osxLocale: 'pt',
pluralCategoryNames: ['one', 'other'],
pluralRules: '(n != 1)',
pluralExamples: ['1', '0, 2-999; 1.2, 2.07...'],
textDirection: 'ltr',
dialectOf: null,
},
];

it('should replace language placeholders', () => {
const str1 = '/folder/%locale%/%three_letters_code%/file1.csv';
Expand Down

0 comments on commit 4c8b4f6

Please sign in to comment.