Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.util.DisplayMetrics;

import androidx.annotation.NonNull;

Expand All @@ -34,7 +33,6 @@
import org.json.JSONObject;

import java.util.Iterator;
import java.util.Locale;

@ReactModule(name = AzifaceMobileModule.NAME)
public class AzifaceMobileModule extends NativeAzifaceMobileSpec implements ActivityEventListener {
Expand Down Expand Up @@ -354,16 +352,13 @@ private void updateTheme() {
}

private void setupI18n() {
Locale locale = new Locale(I18n.getLocale());
final Configuration configuration = new Configuration(this.reactContext.getResources().getConfiguration());
configuration.setLocale(I18n.getLocale());

final Resources resources = this.reactContext.getBaseContext().getResources();
final DisplayMetrics displayMetrics = resources.getDisplayMetrics();
Configuration configuration = resources.getConfiguration();
configuration.setLocale(locale);

resources.updateConfiguration(configuration, displayMetrics);

this.reactContext.getApplicationContext().getResources().updateConfiguration(configuration, displayMetrics);
final Resources resources = this.reactContext.createConfigurationContext(configuration).getResources();
Strings.setResources(resources)
.load()
.build();
}

private void onInitializationSuccess(FaceTecSDKInstance sdkInstance) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import androidx.annotation.NonNull;

import java.util.Locale;

public class Localization {
public static final String DEFAULT = "en";

Expand All @@ -13,8 +15,8 @@ public Localization() {
}

@NonNull
public String getLocale() {
return this.locale;
public Locale getLocale() {
return Locale.forLanguageTag(this.locale);
}

public void setLocale(@NonNull String locale) {
Expand All @@ -36,7 +38,7 @@ public void setLocale(@NonNull String locale) {
this.locale = temp;
break;
case "pt-br":
this.locale = "pt";
this.locale = "pt-BR";
break;
default:
this.locale = "en";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.azifacemobile.strings;

import android.content.res.Resources;

import com.azifacemobile.R;
import com.facebook.react.bridge.ReadableMap;
import com.facetec.sdk.FaceTecSDK;
Expand All @@ -13,11 +15,13 @@ public class DynamicStrings {
Map<Integer, String> dynamicStrings;
@Nullable ReadableMap strings;
@Nullable ReadableMap target;
@Nullable Resources resources;

public DynamicStrings() {
this.dynamicStrings = new HashMap<>();
this.strings = null;
this.target = null;
this.resources = null;
}

@Nullable
Expand Down Expand Up @@ -286,6 +290,12 @@ public DynamicStrings setStrings(@Nullable ReadableMap strings) {
return this;
}

public DynamicStrings setResources(@Nullable Resources resources) {
this.resources = resources;

return this;
}

public DynamicStrings load() {
this.accessibility();
this.accessibilityFeedback();
Expand All @@ -302,6 +312,14 @@ public DynamicStrings load() {
}

public void build() {
if (this.resources != null) {
for (Map.Entry<Integer, String> entry : this.dynamicStrings.entrySet()) {
if (entry.getValue() == null) {
entry.setValue(this.resources.getString(entry.getKey()));
}
}
}

FaceTecSDK.setDynamicStrings(this.dynamicStrings);

this.cleanup();
Expand Down
Loading