Skip to content

Commit f5f0240

Browse files
ReVanced BotLisoUseInAIKyrios
andauthored
feat: Add translations (#2963)
Co-authored-by: LisoUseInAIKyrios <[email protected]>
1 parent c5f0bc4 commit f5f0240

File tree

81 files changed

+49405
-10
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+49405
-10
lines changed

src/main/kotlin/app/revanced/patches/all/misc/resources/AddResourcesPatch.kt

Lines changed: 100 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import app.revanced.util.resource.BaseResource
1313
import app.revanced.util.resource.StringResource
1414
import org.w3c.dom.Node
1515
import java.io.Closeable
16-
import java.util.*
1716

1817
/**
1918
* An identifier of an app. For example, `youtube`.
@@ -55,6 +54,95 @@ object AddResourcesPatch : ResourcePatch(), MutableMap<Value, MutableSet<BaseRes
5554
*/
5655
private lateinit var resources: Map<Value, Resources>
5756

57+
/**
58+
* Map of Crowdin locales to Android resource locale names.
59+
*
60+
* Fixme: Instead this patch should detect what locale regions are present in both patches and the target app,
61+
* and automatically merge into the appropriate existing target file.
62+
* So if a target app has only 'es', then the Crowdin file of 'es-rES' should merge into that.
63+
* But if a target app has specific regions (such as 'pt-rBR'),
64+
* then the Crowdin region specific file should merged into that.
65+
*/
66+
private val locales = mapOf(
67+
"af-rZA" to "af",
68+
"am-rET" to "am",
69+
"ar-rSA" to "ar",
70+
"as-rIN" to "as",
71+
"az-rAZ" to "az",
72+
"be-rBY" to "be",
73+
"bg-rBG" to "bg",
74+
"bn-rBD" to "bn",
75+
"bs-rBA" to "bs",
76+
"ca-rES" to "ca",
77+
"cs-rCZ" to "cs",
78+
"da-rDK" to "da",
79+
"de-rDE" to "de",
80+
"el-rGR" to "el",
81+
"es-rES" to "es",
82+
"et-rEE" to "et",
83+
"eu-rES" to "eu",
84+
"fa-rIR" to "fa",
85+
"fi-rFI" to "fi",
86+
"tl-rPH" to "tl",
87+
"fr-rFR" to "fr",
88+
"gl-rES" to "gl",
89+
"gu-rIN" to "gu",
90+
"hi-rIN" to "hi",
91+
"hr-rHR" to "hr",
92+
"hu-rHU" to "hu",
93+
"hy-rAM" to "hy",
94+
"in-rID" to "in",
95+
"is-rIS" to "is",
96+
"it-rIT" to "it",
97+
"iw-rIL" to "iw",
98+
"ja-rJP" to "ja",
99+
"ka-rGE" to "ka",
100+
"kk-rKZ" to "kk",
101+
"km-rKH" to "km",
102+
"kn-rIN" to "kn",
103+
"ko-rKR" to "ko",
104+
"ky-rKG" to "ky",
105+
"lo-rLA" to "lo",
106+
"lt-rLT" to "lt",
107+
"lv-rLV" to "lv",
108+
"mk-rMK" to "mk",
109+
"ml-rIN" to "ml",
110+
"mn-rMN" to "mn",
111+
"mr-rIN" to "mr",
112+
"ms-rMY" to "ms",
113+
"my-rMM" to "my",
114+
"nb-rNO" to "nb",
115+
"ne-rIN" to "ne",
116+
"nl-rNL" to "nl",
117+
"or-rIN" to "or",
118+
"pa-rIN" to "pa",
119+
"pl-rPL" to "pl",
120+
"pt-rBR" to "pt-rBR",
121+
"pt-rPT" to "pt-rPT",
122+
"ro-rRO" to "ro",
123+
"ru-rRU" to "ru",
124+
"si-rLK" to "si",
125+
"sk-rSK" to "sk",
126+
"sl-rSI" to "sl",
127+
"sq-rAL" to "sq",
128+
"sr-rSP" to "sr",
129+
"sv-rSE" to "sv",
130+
"sw-rKE" to "sw",
131+
"ta-rIN" to "ta",
132+
"te-rIN" to "te",
133+
"th-rTH" to "th",
134+
"tl-rPH" to "tl",
135+
"tr-rTR" to "tr",
136+
"uk-rUA" to "uk",
137+
"ur-rIN" to "ur",
138+
"uz-rUZ" to "uz",
139+
"vi-rVN" to "vi",
140+
"zh-rCN" to "zh-rCN",
141+
"zh-rHK" to "zh-rHK",
142+
"zh-rTW" to "zh-rTW",
143+
"zu-rZA" to "zu",
144+
)
145+
58146
/*
59147
The strategy of this patch is to stage resources present in `/resources/addresources`.
60148
These resources are organized by their respective value and patch.
@@ -75,23 +163,25 @@ object AddResourcesPatch : ResourcePatch(), MutableMap<Value, MutableSet<BaseRes
75163
/**
76164
* Puts resources under `/resources/addresources/<value>/<resourceKind>.xml` into the map.
77165
*
78-
* @param value The value of the resource. For example, `values` or `values-de`.
166+
* @param sourceValue The source value of the resource. For example, `values` or `values-de-rDE`.
167+
* @param destValue The destination value of the resource. For example, 'values' or 'values-de'.
79168
* @param resourceKind The kind of the resource. For example, `strings` or `arrays`.
80169
* @param transform A function that transforms the [Node]s from the XML files to a [BaseResource].
81170
*/
82171
fun addResources(
83-
value: Value,
172+
sourceValue: Value,
173+
destValue: Value = sourceValue,
84174
resourceKind: String,
85175
transform: (Node) -> BaseResource,
86176
) {
87177
inputStreamFromBundledResource(
88178
"addresources",
89-
"$value/$resourceKind.xml",
179+
"$sourceValue/$resourceKind.xml",
90180
)?.let { stream ->
91181
// Add the resources associated with the given value to the map,
92182
// instead of overwriting it.
93183
// This covers the example case such as adding strings and arrays of the same value.
94-
getOrPut(value, ::mutableMapOf).apply {
184+
getOrPut(destValue, ::mutableMapOf).apply {
95185
context.xmlEditor[stream].use { editor ->
96186
val document = editor.file
97187

@@ -121,13 +211,13 @@ object AddResourcesPatch : ResourcePatch(), MutableMap<Value, MutableSet<BaseRes
121211
// Staged resources consumed by AddResourcesPatch#invoke(PatchClass)
122212
// are later used in AddResourcesPatch#close.
123213
try {
124-
val addStringResources = { value: Value ->
125-
addResources(value, "strings", StringResource::fromNode)
214+
val addStringResources = { source: Value, dest: Value ->
215+
addResources(source, dest, "strings", StringResource::fromNode)
126216
}
127-
Locale.getISOLanguages().asSequence().map { "values-$it" }.forEach { addStringResources(it) }
128-
addStringResources("values")
217+
locales.forEach { (source, dest) -> addStringResources("values-$source", "values-$dest") }
218+
addStringResources("values", "values")
129219

130-
addResources("values", "arrays", ArrayResource::fromNode)
220+
addResources("values", "values", "arrays", ArrayResource::fromNode)
131221
} catch (e: Exception) {
132222
throw PatchException("Failed to read resources", e)
133223
}

0 commit comments

Comments
 (0)