From e0480eb093bd3b6e94864b18dd6c63107ac6758c Mon Sep 17 00:00:00 2001 From: Derick M <58572875+TurtIeSocks@users.noreply.github.com> Date: Thu, 20 Apr 2023 14:08:27 -0400 Subject: [PATCH] add support for custom translation endpoints --- package.json | 2 +- src/classes/Translations.ts | 25 ++++++++++++++++++------- src/index.ts | 4 +++- src/typings/inputs.ts | 2 ++ yarn.lock | 6 +++--- 5 files changed, 27 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 3bc560a..24c973d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pogo-data-generator", - "version": "1.11.1", + "version": "1.11.2", "description": "Pokemon GO project data generator", "author": "TurtIeSocks", "license": "Apache-2.0", diff --git a/src/classes/Translations.ts b/src/classes/Translations.ts index 3f2bfc9..d705967 100644 --- a/src/classes/Translations.ts +++ b/src/classes/Translations.ts @@ -15,6 +15,8 @@ import Masterfile from './Masterfile' export default class Translations extends Masterfile { options: Options + translationApkUrl: string + translationRemoteUrl: string rawTranslations: TranslationKeys manualTranslations: { [key: string]: TranslationKeys } parsedTranslations: { [key: string]: TranslationKeys } @@ -25,13 +27,20 @@ export default class Translations extends Masterfile { enFallback: TranslationKeys collator: Intl.Collator - constructor(options: Options) { + constructor( + options: Options, + translationApkUrl = 'https://raw.githubusercontent.com/PokeMiners/pogo_assets/master/Texts/Latest%20APK/JSON/i18n_english.json', + translationRemoteUrl = 'https://raw.githubusercontent.com/PokeMiners/pogo_assets/master/Texts/Latest%20Remote/English.txt', + ) { super() this.collator = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base', }) this.options = options + this.translationApkUrl = translationApkUrl + this.translationRemoteUrl = translationRemoteUrl + this.rawTranslations = {} this.manualTranslations = {} this.parsedTranslations = {} @@ -178,9 +187,10 @@ export default class Translations extends Masterfile { console.warn(`Generics unavailable for ${locale}, using English`) } const { data }: { data: string[] } = (await this.fetch( - `https://raw.githubusercontent.com/PokeMiners/pogo_assets/master/Texts/Latest%20APK/JSON/i18n_${ - this.codes[locale]?.toLowerCase() || 'english' - }.json`, + this.translationApkUrl.replace( + 'english', + this.codes[locale]?.toLowerCase() || 'english', + ), )) || { data: [] } for (let i = 0; i < data.length; i += 2) { @@ -190,9 +200,10 @@ export default class Translations extends Masterfile { const textFile = ['hi', 'id'].includes(locale) ? '' : (await this.fetch( - `https://raw.githubusercontent.com/PokeMiners/pogo_assets/master/Texts/Latest%20Remote/${ - this.codes[locale] || 'English' - }.txt`, + this.translationRemoteUrl.replace( + 'English', + this.codes[locale] || 'English', + ), true, )) || '' const splitText = textFile.split('\n') diff --git a/src/index.ts b/src/index.ts index ba797df..4c93d1a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -24,6 +24,8 @@ import { NiaMfObj } from './typings/general' export async function generate({ template, url, + translationApkUrl, + translationRemoteUrl, raw, pokeApi, test, @@ -55,7 +57,7 @@ export async function generate({ const AllInvasions = new Invasions(invasions.options) const AllTypes = new Types() const AllWeather = new Weather() - const AllTranslations = new Translations(translations.options) + const AllTranslations = new Translations(translations.options, translationApkUrl, translationRemoteUrl) const AllPokeApi = new PokeApi() const data: NiaMfObj[] = await AllPokemon.fetch(urlToFetch) diff --git a/src/typings/inputs.ts b/src/typings/inputs.ts index 8fecb9c..f603108 100644 --- a/src/typings/inputs.ts +++ b/src/typings/inputs.ts @@ -253,6 +253,8 @@ export interface TranslationsTemplate { export interface Input { url?: string + translationApkUrl?: string + translationRemoteUrl?: string template?: FullTemplate test?: boolean raw?: boolean diff --git a/yarn.lock b/yarn.lock index 907cb8e..bff6acf 100644 --- a/yarn.lock +++ b/yarn.lock @@ -861,9 +861,9 @@ integrity sha512-6qKpDtoaYLM+5+AFChLhHermMQxc3TOEFIDzrZLPRGHPrLEwqFkkT5Kx3ju05g6X7uDPazz3jHbKPX0KzCjntg== "@types/node@>=13.7.0": - version "18.15.11" - resolved "https://registry.yarnpkg.com/@types/node/-/node-18.15.11.tgz#b3b790f09cb1696cffcec605de025b088fa4225f" - integrity sha512-E5Kwq2n4SbMzQOn6wnmBjuK9ouqlURrcZDVfbo9ftDDTFt3nk7ZKK4GMOzoYgnpQJKcxwQw+lGaBvvlMo0qN/Q== + version "18.15.12" + resolved "https://registry.yarnpkg.com/@types/node/-/node-18.15.12.tgz#833756634e78c829e1254db006468dadbb0c696b" + integrity sha512-Wha1UwsB3CYdqUm2PPzh/1gujGCNtWVUYF0mB00fJFoR4gTyWTDPjSm+zBF787Ahw8vSGgBja90MkgFwvB86Dg== "@types/prettier@^2.1.5": version "2.6.4"