gluon mobile android application default locale is en_US but phone is in spanish

Viewed 65

i test i18n in gluon with its default project : gluon mobile single view . i add a print line to get : Locale.getdefault() . but is in english en_US and the device is in spanish . i have another large project with bundles and i had the same issue . i put the default project in this question 'cause i found better to show just small portion of code and replicate it . the code

package com.local;

 import com.gluonhq.charm.glisten.control.AppBar;
 import com.gluonhq.charm.glisten.control.Icon;
 import com.gluonhq.charm.glisten.mvc.View;
 import com.gluonhq.charm.glisten.visual.MaterialDesignIcon;
 import java.util.Locale;
 import javafx.geometry.Pos;
 import javafx.scene.control.Button;
 import javafx.scene.control.Label;
 import javafx.scene.layout.VBox;

 public class BasicView extends View {

  public BasicView() {
    
    Label label = new Label("Hello JavaFX World!");

    Button button = new Button("Change the World!");
    button.setGraphic(new Icon(MaterialDesignIcon.LANGUAGE));
    button.setOnAction(e -> {label.setText("Hello JavaFX Universe!");
    
    // i add this line to default : gluon mobile single view 
    System.out.println(Locale.getDefault());});
    
    VBox controls = new VBox(15.0, label, button);
    controls.setAlignment(Pos.CENTER);
    
    setCenter(controls);
}

@Override
protected void updateAppBar(AppBar appBar) {
    appBar.setNavIcon(MaterialDesignIcon.MENU.button(e -> System.out.println("Menu")));
    appBar.setTitleText("Basic View");
    appBar.getActionItems().add(MaterialDesignIcon.SEARCH.button(e -> System.out.println("Search")));
}

}

and i get this from console after install .apk on a real device

[vie. mar. 26 17:44:13 CLST 2021][INFO] [SUB] D/GraalCompiled(13989): en_US

pom file :

` <project xmlns="http://maven.apache.org/POM/4.0.0" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven- 
   4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

<groupId>com.local</groupId>
<artifactId>local</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>>local</name>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.release>11</maven.compiler.release>
    <javafx.version>16</javafx.version>
    <attach.version>4.0.11</attach.version>
    <client.plugin.version>0.1.38</client.plugin.version>
    <javafx.plugin.version>0.0.5</javafx.plugin.version>
    <mainClassName>com.local.Local</mainClassName>
</properties>

<dependencies>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-controls</artifactId>
        <version>${javafx.version}</version>
    </dependency>
    <dependency>
        <groupId>com.gluonhq</groupId>
        <artifactId>charm-glisten</artifactId>
        <version>6.0.6</version>
    </dependency>
    <dependency>
        <groupId>com.gluonhq.attach</groupId>
        <artifactId>display</artifactId>
        <version>${attach.version}</version>
    </dependency>
    <dependency>
        <groupId>com.gluonhq.attach</groupId>
        <artifactId>lifecycle</artifactId>
        <version>${attach.version}</version>
    </dependency>
    <dependency>
        <groupId>com.gluonhq.attach</groupId>
        <artifactId>statusbar</artifactId>
        <version>${attach.version}</version>
    </dependency>
    <dependency>
        <groupId>com.gluonhq.attach</groupId>
        <artifactId>storage</artifactId>
        <version>${attach.version}</version>
    </dependency>
    <dependency>
        <groupId>com.gluonhq.attach</groupId>
        <artifactId>util</artifactId>
        <version>${attach.version}</version>
    </dependency>
</dependencies>

<repositories>
    <repository>
        <id>Gluon</id>
        <url>https://nexus.gluonhq.com/nexus/content/repositories/releases</url>
    </repository>
</repositories>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
        </plugin>

        <plugin>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-maven-plugin</artifactId>
            <version>${javafx.plugin.version}</version>
            <configuration>
                <mainClass>${mainClassName}</mainClass>
            </configuration>
        </plugin>

        <plugin>
            <groupId>com.gluonhq</groupId>
            <artifactId>client-maven-plugin</artifactId>
            <version>${client.plugin.version}</version>
            <configuration>
                <target>${client.target}</target>
                <attachList>
                    <list>display</list>
                    <list>lifecycle</list>
                    <list>statusbar</list>
                    <list>storage</list>
                </attachList>
                <mainClass>${mainClassName}</mainClass>
            </configuration>
        </plugin>
    </plugins>
</build>

<profiles>
    <profile>
        <id>desktop</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <client.target>host</client.target>
        </properties>
        <dependencies>
            <dependency>
                <groupId>com.gluonhq.attach</groupId>
                <artifactId>display</artifactId>
                <version>${attach.version}</version>
                <classifier>desktop</classifier>
            </dependency>
            <dependency>
                <groupId>com.gluonhq.attach</groupId>
                <artifactId>lifecycle</artifactId>
                <version>${attach.version}</version>
                <classifier>desktop</classifier>
            </dependency>
            <dependency>
                <groupId>com.gluonhq.attach</groupId>
                <artifactId>storage</artifactId>
                <version>${attach.version}</version>
                <classifier>desktop</classifier>
            </dependency>
        </dependencies>
    </profile>
    <profile>
        <id>ios</id>
        <properties>
            <client.target>ios</client.target>
        </properties>
    </profile>
    <profile>
        <id>android</id>
        <properties>
            <client.target>android</client.target>
        </properties>
    </profile>
</profiles>

`

1 Answers

The problem you are facing is that the locale used to build the native image (usually the default locale on your machine, unless set otherwise) is the one that will be used on runtime, no matter what locale is set.

There is an open issue in GraalVM about this. There is no definitive fix for this yet, but it is expected to be available from GraalVM 21.1 (in just a couple of weeks).

For now, a workaround is to set the target's locale in the Client plugin configuration, like:

<nativeImageArgs>
    <arg>-Duser.language=es</arg>
    <arg>-Duser.country=ES</arg>
</nativeImageArgs>

and then run again

mvn -Pandroid client:build client:package

The generated APK will use the es_ES resource bundles.

Of course, this means that you would have to build a different image/APK for every language you support, which is really inconvenient.

Related