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

Reliance on Deprecated Constructor #30

Open
neuralmer opened this issue Oct 21, 2019 · 1 comment
Open

Reliance on Deprecated Constructor #30

neuralmer opened this issue Oct 21, 2019 · 1 comment

Comments

@neuralmer
Copy link

RestringResources relies on a deprecated constructor. The description about the deprecation is:

Resources should not be constructed by apps. See Context.createConfigurationContext(Configuration).

It appears that replacing the Resources instance with custom one is not something Android intends to support. Any ideas about what to do if they do remove that constructor? I see another public constructor, but its documentation is marked with @hide, for which I would expect an implementation that used it to be equally brittle.

@B3nedikt I think you should add an issues list to your fork. I would have posted this question to there, had it existed. I could understand wanting to have the issues for Restring be in a single place, but having an issues list might give others an idea of how much other people are using your fork.

@B3nedikt
Copy link

B3nedikt commented Nov 1, 2019

That is correct, custom Resources are not supported by android, that's kind of the reason why the getString() methods on Context are final.

I think there are two intended ways to deal with this:

  • Create a copy of the Context and pass this around using DI. Works well for stuff like changing the language of the app, but you can´t actually replace the resources like restring does.
  • Provide a completely new localization system specific for your app, and use it everywhere. This is quite the effort especially for legacy apps. There is a lot to consider like switching language, redrawing etc.

At the moment the way restring does it is the simplest way, I am looking to abstract some stuff away here and make option 2 above easier to implement with a new lib, but I think for legacy apps you don´t really have a choice. Replacing all those getString() calls can be a pain, if they are not properly abstracted away ;)

You could have a look at https://github.com/JcMinarro/Philology.
It uses the same approach as @hamidness original restring, but it is more stable. I think my fork is the way to go if you need more features like applying changes without restarting the activity and changing your apps language, Philology is more lightweight though.

I added an issue list to my fork, I don´t think a lot of people are using it though. I only use it in a single project myself in production :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants