Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Translations): Translations for YouTube and Twitch #2366

Closed
wants to merge 206 commits into from
Closed
Show file tree
Hide file tree
Changes from 161 commits
Commits
Show all changes
206 commits
Select commit Hold shift + click to select a range
c8052e6
move youtube resources into subdirectory
LisoUseInAIKyrios Jun 5, 2023
ed9b6a6
removed all StringResource usage for YouTube
LisoUseInAIKyrios Jun 5, 2023
8b29278
sorting by title now done in integrations
LisoUseInAIKyrios Jun 5, 2023
b4bcc8e
youtube translations
LisoUseInAIKyrios Jun 5, 2023
0d1f405
no longer needed
LisoUseInAIKyrios Jun 5, 2023
6baec1a
use same minimum version as YouTube. Not that it matters.
LisoUseInAIKyrios Jun 5, 2023
5f28ace
cleanup
LisoUseInAIKyrios Jun 5, 2023
024174c
adding annotation, moving code
LisoUseInAIKyrios Jun 6, 2023
f3c0da8
extract strings for twitch
LisoUseInAIKyrios Jun 6, 2023
af0e185
rename class
LisoUseInAIKyrios Jun 6, 2023
9d4f0e2
hide the last bits of StringResource
LisoUseInAIKyrios Jun 6, 2023
e77dbfc
twitch translations stubs
LisoUseInAIKyrios Jun 6, 2023
096581d
no functional changes: renamed classes
LisoUseInAIKyrios Jun 6, 2023
964384e
fixing escaping
LisoUseInAIKyrios Jun 6, 2023
14286a3
fixing twitch
LisoUseInAIKyrios Jun 6, 2023
0c71637
cleanup
LisoUseInAIKyrios Jun 6, 2023
31d8cfe
simplify array resources
LisoUseInAIKyrios Jun 6, 2023
29b86a3
fixing stuff
LisoUseInAIKyrios Jun 6, 2023
76df5f3
comments are in integrations
LisoUseInAIKyrios Jun 6, 2023
b0441ec
more clear
LisoUseInAIKyrios Jun 6, 2023
696475c
strings that don't need, or should not be translated
LisoUseInAIKyrios Jun 6, 2023
98ff8f5
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Jun 7, 2023
d695cc6
fixing merge
LisoUseInAIKyrios Jun 7, 2023
bda7d17
moving YouTube microg strings to localized file
LisoUseInAIKyrios Jun 7, 2023
01c14d5
fixing merge
LisoUseInAIKyrios Jun 7, 2023
12574bc
more non translatable text
LisoUseInAIKyrios Jun 7, 2023
eee722a
added option to throw an exception if destination files exist.
LisoUseInAIKyrios Jun 7, 2023
cdd6d24
Merge branch 'dev' into localization
LisoUseInAIKyrios Jun 8, 2023
0dcd794
move non-translatable strings into separate file.
LisoUseInAIKyrios Jun 8, 2023
0bac41f
comments
LisoUseInAIKyrios Jun 8, 2023
4be097c
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Jun 10, 2023
4c6485e
SponsorBlock has removed the leaderboard (the api end point no longer…
LisoUseInAIKyrios Jun 10, 2023
308b7a7
no functional changes: renamed classes
LisoUseInAIKyrios Jun 10, 2023
5e3c04a
no functional changes: renamed classes
LisoUseInAIKyrios Jun 10, 2023
853e882
tiktok translations
LisoUseInAIKyrios Jun 10, 2023
37c78b8
Revert "tiktok translations"
LisoUseInAIKyrios Jun 10, 2023
18c036a
twitch machine translations
LisoUseInAIKyrios Jun 10, 2023
c174120
turned off, for now
LisoUseInAIKyrios Jun 10, 2023
349cc6e
Merge branch 'dev' into localization
LisoUseInAIKyrios Jun 10, 2023
ba4218c
Merge branch 'dev' into localization
LisoUseInAIKyrios Jun 11, 2023
d40082b
Verify the regex matches the end of the path, in case the user likes …
LisoUseInAIKyrios Jun 11, 2023
db4420b
Merge branch 'dev' into localization
LisoUseInAIKyrios Jun 12, 2023
7b0025b
Merge branch 'dev' into localization
LisoUseInAIKyrios Jun 13, 2023
e25876b
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Jun 15, 2023
4cef4cb
fixing merge
LisoUseInAIKyrios Jun 15, 2023
b699f8d
no point translating this dead patch.
LisoUseInAIKyrios Jun 15, 2023
311cc71
use same ordering as shown in the app.
LisoUseInAIKyrios Jun 15, 2023
d4eb9fb
use revanced prefix
LisoUseInAIKyrios Jun 15, 2023
26358fe
use revanced prefix
LisoUseInAIKyrios Jun 15, 2023
2aff527
fixing stuff
LisoUseInAIKyrios Jun 15, 2023
5b40257
comments
LisoUseInAIKyrios Jun 15, 2023
ee276ba
making resource names more consistent
LisoUseInAIKyrios Jun 16, 2023
22cecb1
Merge branch 'dev' into localization
LisoUseInAIKyrios Jun 16, 2023
357f2a3
logging out is no longer needed nor works, as YouTube now always give…
LisoUseInAIKyrios Jun 16, 2023
63f06d2
Merge remote-tracking branch 'origin/localization' into localization
LisoUseInAIKyrios Jun 16, 2023
e98bffb
adjust strings
LisoUseInAIKyrios Jun 16, 2023
774e81a
Merge branch 'dev' into localization
LisoUseInAIKyrios Jun 16, 2023
bfdbf3a
fixing RTL languages
LisoUseInAIKyrios Jun 16, 2023
5261aea
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Jun 18, 2023
66ecccf
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Jun 18, 2023
9a92dab
finishing merge
LisoUseInAIKyrios Jun 18, 2023
5394766
committing missing resources lost in refactoring
LisoUseInAIKyrios Jun 20, 2023
519b7bb
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Jun 21, 2023
17ba726
Merge branch 'dev' into localization
LisoUseInAIKyrios Jun 22, 2023
c2d146f
Adding last untranslated strings.
LisoUseInAIKyrios Jun 22, 2023
4dc1242
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Jun 23, 2023
d6947b0
finishing merge
LisoUseInAIKyrios Jun 23, 2023
7dd42c9
downloading appears to be working again.
LisoUseInAIKyrios Jun 25, 2023
69363f9
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Jun 28, 2023
a155350
this should be the last non-localized string
LisoUseInAIKyrios Jun 28, 2023
e5d4e82
Merge branch 'revanced:main' into localization
LisoUseInAIKyrios Jul 1, 2023
dbafeb1
Merge branch 'dev' into localization
LisoUseInAIKyrios Jul 1, 2023
87ce721
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Jul 3, 2023
4492623
finishing merge
LisoUseInAIKyrios Jul 3, 2023
12d50bc
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Jul 5, 2023
7ee8319
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Jul 6, 2023
7e01c93
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Jul 8, 2023
e906b41
Merge branch 'dev' into localization
LisoUseInAIKyrios Jul 8, 2023
6b120ea
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Jul 11, 2023
3c99acb
resolving merge specific conflicts
LisoUseInAIKyrios Jul 11, 2023
cb37081
fixing merge
LisoUseInAIKyrios Jul 11, 2023
66365f0
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Jul 14, 2023
1c9c100
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Jul 16, 2023
4d684b0
fixing merge
LisoUseInAIKyrios Jul 16, 2023
5b480c3
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Jul 19, 2023
ea26235
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Jul 20, 2023
75154a3
merge specific updates changes
LisoUseInAIKyrios Jul 20, 2023
f32c942
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Jul 20, 2023
31d4586
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Jul 21, 2023
e607a46
merge specific changes
LisoUseInAIKyrios Jul 21, 2023
d8d13a0
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Jul 22, 2023
c7abe2a
Use latest patch naming
LisoUseInAIKyrios Jul 22, 2023
1ca4b81
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Jul 28, 2023
bd48c39
merge specific changes
LisoUseInAIKyrios Jul 28, 2023
6b21039
fixing merge
LisoUseInAIKyrios Jul 28, 2023
4f45656
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Jul 30, 2023
6da28e3
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Jul 30, 2023
86a698b
merge specific changes
LisoUseInAIKyrios Jul 30, 2023
1d73b48
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Aug 1, 2023
dd13f20
remove deprecated version annotation
LisoUseInAIKyrios Aug 1, 2023
eed733b
fixing string
LisoUseInAIKyrios Aug 1, 2023
dab6548
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Aug 3, 2023
94fb588
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Aug 6, 2023
f81af8b
merge specific changes
LisoUseInAIKyrios Aug 6, 2023
a5f5255
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Aug 6, 2023
f220bae
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Aug 7, 2023
329df81
merge specific changes
LisoUseInAIKyrios Aug 7, 2023
7ec5996
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Aug 7, 2023
9b15c4d
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Aug 7, 2023
9b67a99
merge specific changes
LisoUseInAIKyrios Aug 7, 2023
58ea296
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Aug 7, 2023
284096a
merge specific changes
LisoUseInAIKyrios Aug 7, 2023
a5337eb
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Aug 23, 2023
24a6aff
merge specific changes
LisoUseInAIKyrios Aug 23, 2023
470485b
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Aug 24, 2023
607816c
distinct names from other integration patches
LisoUseInAIKyrios Aug 24, 2023
1e2afc0
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Aug 26, 2023
8e2c187
fixing merge conflicts
LisoUseInAIKyrios Aug 26, 2023
8135f90
fixing merge
LisoUseInAIKyrios Aug 27, 2023
a81e8cb
revert "AppNameSettingsPatch" back to just "SettingsPatch"
LisoUseInAIKyrios Sep 5, 2023
1770d12
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Sep 7, 2023
6a86ca9
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Sep 8, 2023
7066824
extracted strings to individual patch files
LisoUseInAIKyrios Sep 10, 2023
27f6c4f
Code to merge English strings into a single xml file, and gradle task…
LisoUseInAIKyrios Sep 10, 2023
3f9ef71
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Sep 14, 2023
c340575
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Sep 15, 2023
3c8db65
Moved Twitch strings to individual files
LisoUseInAIKyrios Sep 15, 2023
bfd6271
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Sep 18, 2023
0bc62b2
extract string
LisoUseInAIKyrios Sep 18, 2023
bad9f9d
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Sep 20, 2023
3cc26cc
fixing merge
LisoUseInAIKyrios Sep 20, 2023
72e2ed5
chore(release): 2.191.0-dev.6 [skip ci]
semantic-release-bot Sep 22, 2023
715aef8
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Sep 22, 2023
1500420
cleanup of merge
LisoUseInAIKyrios Sep 22, 2023
b31fec3
fixing initialization error
LisoUseInAIKyrios Sep 22, 2023
7eef4b2
Fixing missing string. Desperately need to hook aapt up to the conso…
LisoUseInAIKyrios Sep 22, 2023
489bfbe
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Sep 23, 2023
0b2c5a4
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Sep 24, 2023
649e5f0
merge specific changes
LisoUseInAIKyrios Sep 24, 2023
fba965a
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Sep 25, 2023
1624b66
merge specific changes
LisoUseInAIKyrios Sep 25, 2023
dffccce
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Sep 25, 2023
ec90583
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Sep 26, 2023
09d5b83
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Oct 2, 2023
e81eb88
merge specific changes
LisoUseInAIKyrios Oct 2, 2023
42e7dc9
refactor: rename string file to match pat
LisoUseInAIKyrios Oct 2, 2023
92e71e8
merge specific updates
LisoUseInAIKyrios Oct 2, 2023
514de4d
refactor: no functional changes: rearrange strings to the same order …
LisoUseInAIKyrios Oct 2, 2023
642f900
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Oct 3, 2023
6fcc0e6
merge specific changes
LisoUseInAIKyrios Oct 3, 2023
c0c2fc2
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Oct 14, 2023
82012ef
merge specific changes
LisoUseInAIKyrios Oct 14, 2023
e9f17b4
Validate strings have been merged before using, since resource compil…
LisoUseInAIKyrios Oct 14, 2023
3b7ab0b
fix importing wrong class
LisoUseInAIKyrios Oct 14, 2023
3940670
Merge branch 'dev' into localization
LisoUseInAIKyrios Oct 14, 2023
0630f7a
Update src/main/kotlin/app/revanced/util/resources/ResourceUtils.kt
LisoUseInAIKyrios Oct 14, 2023
9f097d4
importing duplicate strings almost always indicates an problem
LisoUseInAIKyrios Oct 14, 2023
fd43e61
description
LisoUseInAIKyrios Oct 14, 2023
b5ee03b
Comments
LisoUseInAIKyrios Oct 14, 2023
44024c0
Sorting is now done in integrations based on the localized language i…
LisoUseInAIKyrios Oct 14, 2023
9938eec
correctly handle `formatted="true"`
LisoUseInAIKyrios Oct 14, 2023
665e79e
refactor: Slight refactoring
oSumAtrIX Oct 14, 2023
c2ce152
no functional changes: rename methods and comments
LisoUseInAIKyrios Oct 14, 2023
be2f234
removing as it's generated.
LisoUseInAIKyrios Oct 14, 2023
4b73834
remove gradle merge task, as it appears CrowdIn will work as desired …
LisoUseInAIKyrios Oct 14, 2023
37ff920
No functional changes: renamed Utils classes.
LisoUseInAIKyrios Oct 14, 2023
50e34e2
fixing merge
LisoUseInAIKyrios Oct 14, 2023
d78aac0
fixing overlooked refactor
LisoUseInAIKyrios Oct 15, 2023
d33028e
Comments
LisoUseInAIKyrios Oct 15, 2023
afd9465
refactor: Use `SettingsPatch` instead of `SettingsResourcePath`
oSumAtrIX Oct 16, 2023
155ab5e
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Oct 31, 2023
81cb847
merge specific changes
LisoUseInAIKyrios Oct 31, 2023
4573811
extract Strings bundling into it's own patch
LisoUseInAIKyrios Oct 31, 2023
7df1cee
fix typo
LisoUseInAIKyrios Oct 31, 2023
48b9466
comments
LisoUseInAIKyrios Oct 31, 2023
2a1bd8b
removed resource callback that is no longer needed
LisoUseInAIKyrios Oct 31, 2023
9b21fad
comments
LisoUseInAIKyrios Oct 31, 2023
35fa271
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Nov 5, 2023
282dd81
merge specific changes
LisoUseInAIKyrios Nov 5, 2023
4eab894
No longer need to check since resource compilation now shows errors
LisoUseInAIKyrios Nov 5, 2023
80f3e91
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Nov 6, 2023
56587eb
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Nov 10, 2023
c55ca6e
merge specific changes
LisoUseInAIKyrios Nov 10, 2023
ec4745b
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Nov 11, 2023
4eabbc1
merge specific changes
LisoUseInAIKyrios Nov 11, 2023
8d59193
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Nov 13, 2023
2056fda
merge specific changes
LisoUseInAIKyrios Nov 13, 2023
b869ab1
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Nov 17, 2023
f0404e1
merge specific changes
LisoUseInAIKyrios Nov 17, 2023
261b130
feat(YouTube):Add `Disable rolling number animations` patch (#3298)
LisoUseInAIKyrios Nov 19, 2023
a3e275b
fix(Twitch - Settings): Constrain to last working version
oSumAtrIX Nov 19, 2023
9b855f0
fix(Yuka - Unlock premium): Constrain to last working version
oSumAtrIX Nov 19, 2023
2fbf17d
chore(release): 2.198.1-dev.2 [skip ci]
semantic-release-bot Nov 19, 2023
f3b3b24
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Nov 20, 2023
2f3a13f
merge specific changes
LisoUseInAIKyrios Nov 20, 2023
0240466
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Nov 23, 2023
635664f
merge specific changes
LisoUseInAIKyrios Nov 23, 2023
83558e2
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Nov 26, 2023
f4c35f1
merge specific changes
LisoUseInAIKyrios Nov 26, 2023
a8619fd
extract strings
LisoUseInAIKyrios Nov 28, 2023
dc1959f
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Nov 28, 2023
36f1a50
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Nov 30, 2023
9bfd661
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Dec 2, 2023
2929ad3
Merge remote-tracking branch 'upstream/dev' into localization
LisoUseInAIKyrios Dec 10, 2023
4cdfc9b
added shared string patch support. added better exception logging if…
LisoUseInAIKyrios Dec 10, 2023
dbc5485
rearrange packages
LisoUseInAIKyrios Dec 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,21 @@ tasks {
dependsOn("generateBundle")
dependsOn("generateMeta")
}
register<JavaExec>("generateMergedStrings") {
description = "Generate a merged English strings.xml file used for Crowdin translations"
dependsOn(build)

classpath = sourceSets["main"].runtimeClasspath
mainClass = "app.revanced.util.resources.ResourceUtils"
args = listOf(
// YouTube
"src/main/resources/youtube/settings/host/values/",
"src/main/resources/youtube/settings/raw/strings.xml",
// Twitch
"src/main/resources/twitch/settings/host/values/",
"src/main/resources/twitch/settings/raw/strings.xml"
)
}
}

publishing {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package app.revanced.patches.shared.settings

import app.revanced.patcher.data.ResourceContext
import app.revanced.patcher.patch.PatchException
import app.revanced.patcher.patch.ResourcePatch
import app.revanced.patcher.util.DomFileEditor
import app.revanced.patches.shared.settings.preference.BasePreference
import app.revanced.patches.shared.settings.preference.BaseResource
import app.revanced.patches.shared.settings.preference.addPreference
import app.revanced.patches.shared.settings.preference.addResource
import app.revanced.patches.shared.settings.preference.impl.ArrayResource
import app.revanced.patches.shared.settings.preference.impl.StringResource
import app.revanced.util.resources.ResourceUtils
import app.revanced.util.resources.ResourceUtils.copyResources
import org.w3c.dom.Document
import org.w3c.dom.Node
import java.io.Closeable

Expand Down Expand Up @@ -56,7 +57,7 @@ abstract class AbstractSettingsResourcePatch(
private var stringsNode: Node? = null
private var arraysNode: Node? = null

private var strings = mutableListOf<StringResource>()
private var strings = mutableMapOf<String, StringResource>()

private var revancedPreferencesEditor: DomFileEditor? = null
set(value) {
Expand All @@ -75,7 +76,7 @@ abstract class AbstractSettingsResourcePatch(
}

/**
* Add a new string to the resources.
* Add a new English string to the resources.
*
* @param identifier The key of the string.
* @param value The value of the string.
Expand All @@ -84,6 +85,20 @@ abstract class AbstractSettingsResourcePatch(
fun addString(identifier: String, value: String, formatted: Boolean) =
StringResource(identifier, value, formatted).include()

/**
* Verifies a String resource with the given key has been merged.
*
* Should be used everywhere a String resource is referenced,
* as missing resources will fail to compile and usually give no feedback to what's wrong.
*
* @throws PatchException
*/
internal fun validateStringIsMerged(key: String): String {
if (!strings.contains(key))
throw PatchException("Unknown String resource: '$key' Merge patch strings before referencing.")
return key
}

/**
* Add an array to the resources.
*
Expand All @@ -108,10 +123,10 @@ abstract class AbstractSettingsResourcePatch(
internal fun BaseResource.include() {
when (this) {
is StringResource -> {
if (strings.any { it.name == name }) return
strings.add(this)
if (strings.put(name, this) != null) {
throw PatchException("Tried to add duplicate string: $name")
}
}

is ArrayResource -> addArray(this)
else -> throw NotImplementedError("Unsupported resource type")
}
Expand All @@ -122,12 +137,34 @@ abstract class AbstractSettingsResourcePatch(

override fun close() {
// merge all strings, skip duplicates
strings.forEach {
strings.values.forEach {
stringsNode!!.addResource(it)
}

revancedPreferencesEditor?.close()
stringsEditor?.close()
arraysEditor?.close()
}
}

/**
* Legacy code used to merge non translated English strings into the Strings.xml file.
*
* @param name The name of the string.
* @param value The value of the string.
* @param formatted If the string is formatted. If false, the attribute will be set.
*/
private class StringResource(
name: String,
val value: String,
val formatted: Boolean = true
) : BaseResource(name, "string") {

override fun serialize(ownerDocument: Document, resourceCallback: (BaseResource) -> Unit) =
super.serialize(ownerDocument, resourceCallback).apply {
// if the string is un-formatted, explicitly add the formatted attribute
if (!formatted) setAttribute("formatted", "false")

textContent = value
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package app.revanced.patches.shared.settings.preference

import app.revanced.patches.shared.settings.preference.impl.StringResource
import app.revanced.patches.shared.settings.AbstractSettingsResourcePatch
import app.revanced.patches.shared.settings.AbstractSettingsResourcePatch.Companion.validateStringIsMerged
import org.w3c.dom.Document
import org.w3c.dom.Element

/**
* Base preference class for all preferences.
*
* @param key The key of the preference.
* @param title The title of the preference.
* @param titleKey The title of the preference.
* @param tag The tag of the preference.
* @param summary The summary of the preference.
* @param summaryKey The summary of the preference.
*/
abstract class BasePreference(
val key: String?,
val title: StringResource,
val summary: StringResource? = null,
val titleKey: String,
val summaryKey: String? = null,
val tag: String
) {
/**
Expand All @@ -28,7 +29,7 @@ abstract class BasePreference(
open fun serialize(ownerDocument: Document, resourceCallback: (BaseResource) -> Unit): Element =
oSumAtrIX marked this conversation as resolved.
Show resolved Hide resolved
ownerDocument.createElement(tag).apply {
if (key != null) setAttribute("android:key", key)
setAttribute("android:title", "@string/${title.also { resourceCallback.invoke(it) }.name}")
addSummary(summary?.also { resourceCallback.invoke(it) })
setAttribute("android:title", "@string/${validateStringIsMerged(titleKey)}")
addSummary(summaryKey)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package app.revanced.patches.shared.settings.preference

import app.revanced.patches.shared.settings.preference.impl.StringResource
import app.revanced.patches.shared.settings.AbstractSettingsResourcePatch
import app.revanced.patches.shared.settings.AbstractSettingsResourcePatch.Companion.validateStringIsMerged
import org.w3c.dom.Element
import org.w3c.dom.Node

Expand All @@ -24,10 +25,11 @@ internal fun Node.addPreference(preference: BasePreference, resourceCallback: ((
appendChild(preference.serialize(ownerDocument, resourceCallback))
}

internal fun Element.addSummary(summaryResource: StringResource?, summaryType: SummaryType = SummaryType.DEFAULT) =
summaryResource?.let { summary ->
setAttribute("android:${summaryType.type}", "@string/${summary.name}")
internal fun Element.addSummary(summaryResourceKey: String?, summaryType: SummaryType = SummaryType.DEFAULT) {
if (summaryResourceKey != null) {
setAttribute("android:${summaryType.type}", "@string/${validateStringIsMerged(summaryResourceKey)}")
}
}

internal fun <T> Element.addDefault(default: T) {
if (default is Boolean && !(default as Boolean)) return // No need to include the default, as no value already means 'false'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
package app.revanced.patches.shared.settings.preference

import app.revanced.patches.shared.settings.preference.impl.StringResource
import org.w3c.dom.Document

/**
* Base preference class that also has a default value.
*
* @param key The key of the preference.
* @param title The title of the preference.
* @param titleKey The title of the preference.
* @param tag The tag of the preference.
* @param summary The summary of the preference.
* @param summaryKey The summary of the preference.
* @param default The default value of the preference.
*/
abstract class DefaultBasePreference<T>(
key: String?,
title: StringResource,
summary: StringResource? = null,
titleKey: String,
summaryKey: String? = null,
tag: String,
val default: T? = null,
) : BasePreference(key, title, summary, tag) {
) : BasePreference(key, titleKey, summaryKey, tag) {

/**
* Serialize preference element to XML.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
package app.revanced.patches.shared.settings.preference.impl

import app.revanced.patches.shared.settings.AbstractSettingsResourcePatch.Companion.validateStringIsMerged
import app.revanced.patches.shared.settings.preference.BaseResource
import org.w3c.dom.Document

// TODO: allow specifying an array resource file instead of using a list of StringResources
/**
* An array resource.
*
* @param name The name of the array resource.
* @param items The items of the array resource.
* @param literalValues If the values are to be used exactly as is.
* If false, the values are treated as Strings.xml entries.
*/
class ArrayResource(
name: String,
val items: List<StringResource>
val items: Iterable<String>,
val literalValues : Boolean = false
) : BaseResource(name, "string-array") {

override fun serialize(ownerDocument: Document, resourceCallback: (BaseResource) -> Unit) =
super.serialize(ownerDocument, resourceCallback).apply {
setAttribute("name", name)

items.forEach { item ->
resourceCallback.invoke(item)

this.appendChild(ownerDocument.createElement("item").also { itemNode ->
itemNode.textContent = "@string/${item.name}"
itemNode.textContent = if (literalValues) item else "@string/${validateStringIsMerged(item)}"
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,29 @@ import org.w3c.dom.Document
* List preference.
*
* @param key The key of the list preference.
* @param title The title of the list preference.
* @param titleKey The title of the list preference.
* @param entries The human-readable entries of the list preference.
* @param entryValues The entry values of the list preference.
* @param summary The summary of the list preference.
* @param summaryKey The summary of the list preference.
* @param default The default entry value of the list preference.
*/
class ListPreference(
key: String,
title: StringResource,
val entries: ArrayResource,
val entryValues: ArrayResource,
summary: StringResource? = null,
titleKey: String,
val entries: ArrayResource?,
LisoUseInAIKyrios marked this conversation as resolved.
Show resolved Hide resolved
val entryValues: ArrayResource?,
summaryKey: String? = null,
default: String? = null,
) : DefaultBasePreference<String>(key, title, summary, "ListPreference", default) {
) : DefaultBasePreference<String>(key, titleKey, summaryKey, "ListPreference", default) {

override fun serialize(ownerDocument: Document, resourceCallback: (BaseResource) -> Unit) =
super.serialize(ownerDocument, resourceCallback).apply {
setAttribute("android:entries", "@array/${entries.also { resourceCallback.invoke(it) }.name}")
setAttribute("android:entryValues", "@array/${entryValues.also { resourceCallback.invoke(it) }.name}")
addSummary(summary)
if (entries != null) {
setAttribute("android:entries", "@array/${entries.also { resourceCallback.invoke(it) }.name}")
}
if (entryValues != null) {
setAttribute("android:entryValues", "@array/${entryValues.also { resourceCallback.invoke(it) }.name}")
}
addSummary(summaryKey)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ import org.w3c.dom.Element
* Not backed by any preference key/value,
* and cannot be changed by or interacted with by the user.
*
* @param title The title of the preference.
* @param summary The summary of the text preference.
* @param titleKey The title of the preference.
* @param summaryKey The summary of the text preference.
*/
class NonInteractivePreference(
title: StringResource,
summary: StringResource,
) : BasePreference(null, title, summary, "Preference") {
titleKey: String,
summaryKey: String,
) : BasePreference(null, titleKey, summaryKey, "Preference") {
override fun serialize(ownerDocument: Document, resourceCallback: (BaseResource) -> Unit): Element {
return super.serialize(ownerDocument, resourceCallback).apply {
addSummary(summary?.also { resourceCallback.invoke(it)
addSummary(summaryKey?.also {
setAttribute("android:selectable", false.toString())
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,22 @@ import org.w3c.dom.Document
* A preference object.
*
* @param key The key of the preference.
* @param title The title of the preference.
* @param summary The summary of the text preference.
* @param titleKey The title of the preference.
* @param summaryKey The summary of the text preference.
* @param intent The intent of the preference.
*/
class Preference(
key: String,
title: StringResource,
summary: StringResource,
titleKey: String,
summaryKey: String,
val intent: Intent
) : BasePreference(key, title, summary, "Preference") {
) : BasePreference(key, titleKey, summaryKey, "Preference") {

constructor(
title: StringResource,
summary: StringResource,
titleKey: String,
summaryKey: String,
intent: Intent
) : this("", title, summary, intent)
) : this("", titleKey, summaryKey, intent)

override fun serialize(ownerDocument: Document, resourceCallback: (BaseResource) -> Unit) =
super.serialize(ownerDocument, resourceCallback).apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ import org.w3c.dom.Document
* A preference category.
*
* @param key The key of the preference.
* @param title The title of the preference.
* @param titleKey The title of the preference.
* @param preferences Child preferences of this category.
*/
open class PreferenceCategory(
key: String,
title: StringResource,
titleKey: String,
var preferences: List<BasePreference>,
tag: String = "PreferenceCategory"
) : BasePreference(key, title, null, tag) {
) : BasePreference(key, titleKey, null, tag) {

override fun serialize(ownerDocument: Document, resourceCallback: (BaseResource) -> Unit) =
super.serialize(ownerDocument, resourceCallback).apply {
for (childPreference in preferences) {
Expand Down
Loading