-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathmerge-countries.ts
81 lines (61 loc) · 2.16 KB
/
merge-countries.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import fs from 'fs'
import { logger } from './logger'
import { countries } from '@oky/core'
// Temporarily add locales to this array, to chose which locales to merge
const localesToMerge = ['fr']
// Use this to merge object instead of an array
// const itemsObject = {}
// const itemsArray = Object.entries(itemsObject).map(([key, value]) => {
// const values = value as Record<string, string>
// return {
// code: key,
// ...values,
// }
// })
// Temporarily add countries to this array then execute this script to merge them into your /translations submodule
const itemsArray = []
const outputFilepath = './app/src/resources/translations/countries.ts'
// ========================= Merge ========================= //
const mergeArray = () => {
const mergedItems = { ...countries }
itemsArray.forEach((item) => {
const newValues = localesToMerge.reduce((acc, locale) => {
return {
...acc,
[locale]: item[locale],
}
}, {})
mergedItems[item.code] = {
...mergedItems[item.code],
...newValues,
}
})
const outputString = `
import { Locale } from '.'
type Country = Record<Locale, string>
export const countries: Record<string, Country> = ${JSON.stringify(mergedItems)}`
fs.writeFileSync(outputFilepath, outputString)
}
// ========================= Add Locales ========================= //
// *** Edit this to add desired locale to the countries object *** //
const localeToInsert = 'fr'
const addLocale = () => {
const updatedItems = { ...countries }
Object.entries(updatedItems).map(([key, value]) => {
updatedItems[key] = {
...value,
// @ts-ignore
[localeToInsert]: value.en, // TODO: This simply copies the english value
}
})
const outputString = `
import { Locale } from '.'
type Country = Record<Locale, string>
export const countries: Record<string, Country> = ${JSON.stringify(updatedItems)}`
fs.writeFileSync(outputFilepath, outputString)
}
// ========================= Execute ========================= //
// *** Uncomment the function you want to execute *** //
// mergeArray()
// addLocale()
logger('===== EDIT THIS FILE BEFORE EXECUTING IT =====')