Android: Recharge fragment from the same fragment

0

, good to everyone.

My question is this, I am using fragments to show the different views. I have a fragment that is CONFIGURATION, from the, I can among other things, change the language and I do it in the following way

Configuration config = new Configuration();
config.locale = new Locale(idioma);
c.getResources().updateConfiguration(config, null);

The problem I have is that I have to go to another fragment and return to CONFIGURATION, to be able to see the changes in that view, I am not able to restart it or I am not understanding how ... What I can do? Thanks!

    
asked by LcsGrz 16.08.2018 в 20:54
source

1 answer

1

To translate your app you must add all your text to the file string.xml to add a text in this should be done in this way: <string name=”TextView”>Nombre</string> here we add the text name to our file string.xml . To make this text appear in an element, for example a textview just in the text property we add @string/TextView ie the reference to the file string.xml and the name of our string or text.

If we want to add the text by means of code we do it in the same way as if it were a string variable.

After making the changes in our entire app we just have to translate the String.xml and to do it we must create another String.xml but with the translated text. We do this in the following way: For example:

Right-click on the App menu > Res > Values and choose "New Values Resource".

We will automatically see how we are enabled with two new columns: Language and Region. Here we must choose the language and region that correspond to the language to which we are going to translate, for example, "es: Spanish" and "Any Region" so that this translation will be "Spanish" for all Spanish-speaking regions.

We click on "Ok" and voila, a new strings will be created with the icon of the flag of Spain, indicating that this file stores the translation into Spanish.

We just have to fill in this file String.xml but with the text translated into another language.

Once the texts have been changed, our application will already be translated and will be multi-language, loading by default the translation according to the system of our Android.

That is, if your Android is in Spanish, it will load the string.xml suitable for that language, as well as for others.

An example to change the language:

Locale localizacion = new 
Locale("es", "ES");
Locale.setDefault(localizacion);
Configuration config = new 
Configuration();
config.locale = localizacion;
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());

The example is to change to Spanish, but for some languages there are constants as for English:

Locale localizacion =new Locale (Locale.ENGLISH);

Source and more information Class locale

    
answered by 17.08.2018 / 02:41
source