-
Notifications
You must be signed in to change notification settings - Fork 529
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9ebcdeb
commit abcf26c
Showing
8 changed files
with
147 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.bepass.oblivion; | ||
|
||
import android.content.Context; | ||
import android.content.res.Configuration; | ||
import android.content.res.Resources; | ||
import android.util.Log; | ||
import android.util.Pair; | ||
|
||
import java.util.Locale; | ||
|
||
public class LocaleHelper { | ||
private static Locale originalLocale; | ||
|
||
public static void goEn(Context context) { | ||
Resources resources = context.getResources(); | ||
Configuration configuration = resources.getConfiguration(); | ||
originalLocale = configuration.locale; // Save the original locale | ||
|
||
// Change locale to English | ||
configuration.setLocale(new Locale("en")); | ||
resources.updateConfiguration(configuration, resources.getDisplayMetrics()); | ||
} | ||
|
||
public static void restoreLocale(Context context) { | ||
if (originalLocale != null) { | ||
Resources resources = context.getResources(); | ||
Configuration configuration = resources.getConfiguration(); | ||
|
||
// Restore the original locale | ||
configuration.setLocale(originalLocale); | ||
resources.updateConfiguration(configuration, resources.getDisplayMetrics()); | ||
} | ||
} | ||
public static String restoreText(Context context, String text) { | ||
if (originalLocale != null) { | ||
Resources resources = context.getResources(); | ||
// Load the English country names | ||
String[] englishNames = resources.getStringArray(R.array.englishCountries); | ||
This comment has been minimized.
Sorry, something went wrong.
wqerrewetw
Contributor
|
||
restoreLocale(context); | ||
// Load the translated country names | ||
String[] translatedNames = resources.getStringArray(R.array.countries); | ||
|
||
// Find the translated name by matching the English name | ||
for (int i = 0; i < englishNames.length; i++) { | ||
if (englishNames[i].equalsIgnoreCase(text)) { | ||
return translatedNames[i]; | ||
} | ||
} | ||
} | ||
return text; // Return the original text if no translation is found or original locale is not set | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This library is for Jetpack Compose, not for traditional View.