Skip to content

Commit

Permalink
Merge pull request #82 from WatWowMap/custom-translation-endpoints
Browse files Browse the repository at this point in the history
add support for custom translation endpoints
  • Loading branch information
TurtIeSocks authored Apr 20, 2023
2 parents bf0e075 + e0480eb commit b39c069
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
25 changes: 18 additions & 7 deletions src/classes/Translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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 = {}
Expand Down Expand Up @@ -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) {
Expand All @@ -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')
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import { NiaMfObj } from './typings/general'
export async function generate({
template,
url,
translationApkUrl,
translationRemoteUrl,
raw,
pokeApi,
test,
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/typings/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ export interface TranslationsTemplate {

export interface Input {
url?: string
translationApkUrl?: string
translationRemoteUrl?: string
template?: FullTemplate
test?: boolean
raw?: boolean
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit b39c069

Please sign in to comment.