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(AddResourcesPatch): Support adding resources directly from the patch resources with localization for strings in mind #2593
Conversation
…atch resources with localization for strings in mind
…to feat/translations # Conflicts: # src/main/kotlin/app/revanced/patches/all/misc/resources/AddResourcesPatch.kt # src/main/kotlin/app/revanced/patches/twitch/ad/embedded/EmbeddedAdsPatch.kt # src/main/kotlin/app/revanced/patches/twitch/misc/settings/SettingsPatch.kt
@LisoUseInAIKyrios I have gone with something similar to your initial design by asking for a single This structure has been chosen to reduce duplicate json keys. |
If I understand this, all strings would go into the single strings.json file and the strings are grouped by patch/class name. If two different patches use the same strings (such as GMSCore for YouTube and YT Music), how is that handled? |
As of now, the patch reads the strings that match to the current class. For abstracts and so on it would still look up the strings using the class of the abstract class implementation. An approach to solve this would be to pass down the class to the function. This way the abstract class would be used to lookup the strings instead of the implementation of that abstract class. |
…trings for non instantiatable classes
@LisoUseInAIKyrios, I have made a small change regarding this. I have noticed you may be referring to "shared" strings. Similarly to that in #2440. I'd imagine this would be useful if you have say a string "Ok" that would be duplicated across patches. Is there a scenario where this is imaginable? As of now, all patches that share strings also have a common super class in which the strings are present. |
I'm sure a situation can exist where generic strings are shared. But it could be done using this PR as a simple shared patch that only has strings. It might be a little bloated using a patch only to include strings (instead of merging/including a string file) but it would work. |
Another idea I had stashed and deleted was a "shared" object in the JSON similar to the shared package in the patches. Somehow patches could reference the strings and |
@LisoUseInAIKyrios Apart from the remaining TODOs, I've settled with what's pushed. If you do not have any comments, I'll finish with the implementation. One PR change to consider is that the patch reads all resources from the XML files on execution and holds them in memory as |
Yes this plan looks good |
# Conflicts: # api/revanced-patches.api
# [4.0.0-dev.11](v4.0.0-dev.10...v4.0.0-dev.11) (2024-01-17) ### Features * **YouTube:** Support version `19.02.34` ([#2627](#2627)) ([94e08b7](94e08b7))
Nothing else notably happened in this commit despite many lines of code changes
If the XML file is empty, an empty mutable map will be allocated, should not be a problem though
To verify the merging of translations works, one or more non-English languages can be added. Can use machine translations for these. |
The limitation of having literalValues is that either all or no item is a literal, which is odd. Since this parameter found no proper use and items can be manually and individually prefixed with @string, the parameter has been removed
This particularly fixes arrays having "empty" items
I am now finished with this PR, but some mistakes may have still been made:
The merge process will look the following way:
|
src/main/kotlin/app/revanced/patches/all/misc/resources/AddResourcesPatch.kt
Outdated
Show resolved
Hide resolved
src/main/kotlin/app/revanced/patches/twitch/chat/antidelete/ShowDeletedMessagesPatch.kt
Outdated
Show resolved
Hide resolved
src/main/kotlin/app/revanced/patches/twitch/ad/embedded/EmbeddedAdsPatch.kt
Outdated
Show resolved
Hide resolved
src/main/kotlin/app/revanced/patches/twitch/misc/settings/SettingsPatch.kt
Outdated
Show resolved
Hide resolved
I remember one string was "null_summary", so I converted this PR into a draft to find it. This should be as easy as observing StringResource construction |
About
This PR is based on the
music-check-for-gmscore
branch and depends on it being merged.This PR aims to add support for the
AddResourcesPatch
to be able to add resources that are present in the patches. The sidequest it solves this way is to support localization for strings simultaneously by doing that.The PR is heavily inspired by PR #2440 and aims to supersede it in a more generic way by getting rid of a dedicated "translations" patch.
It does so by providing the ability to add strings to a
.json
file in the resources. At the same time, it will add alternative strings in other languages under the same resource directory, such asvalues-de
. In general:resources/addresources/strings.json
tores/values/strings.xml
resources/addresources/values-<language>
tores/values-<language>/strings.xml
BaseResource
to the app's resources such as arraysTodo
The plan is to make each implementation of
BaseResource
handle the logic of adding itself to the app's resources. This way, theAddResourcesPatch
can iterate over itsBaseResource
s and invokeresource.add(...)
, for example, which will make the resource add itself to the corresponding app's resources.This will prevent having to cram everything into
AddResourcesPatch#close
, and in case new kinds ofBaseResource
are implemented (for example, through the public API), the open-closed principle is not violated forAddResourcesPatch#close
AddResourcesPatch
to add resources from the patches resources folder and to be able to add specific resources manually. Some patches may want to add strings or other kinds of resources without creating a resource JSON file in the patches.SettingsPatch
preferences so that they only specify the key just like in feat: Move strings to resources for localization #2440AddResourcesPatch
to all patches that need it