Selecting Font based on device language?

What I am trying to do is the following:

  • For all languages that my custom device supports, load and use my Custom font.
  • For languages that my custom font does not support, load and use the default Garmin font.

Is there an easy way to do this? I tried setting a property in a language not supported then checking for that property to change my font variable to the generic one, but that did not work. I guess I could use the method to find the device language (using the long method since I support 2.x devices) and then just define based on that, but I was kind of hoping that there was an easier way.

Anyone have experience doing this?

Thanks!

  • hi mate,

    unless I did not understand what you need, here is how I do.

    in common @String I put for exemple 

    <string id="LANG">0</string>

    and in the language folders i want to use custom string I put

    <string id="LANG">1</string>

    then, when I load resouces

    font = 0 ;//Gfx.FONT_XTINY (where font is declared at the root)

    var LANG = Ui.loadResource(Rez.Strings.LANG).toNumber();

    if(LANG==1){font=Rez.Fonts.MyCustomFont;}

  • Look are the strings example in the SDK.  It shows how you can use different resources (strings/fonts/etc) based on the language/device.

  • hey! you're on the right track, it's exactly what I'm looking to do. I tried implementing the code and I think I'm close. The issue is, for some reason my app doesn't seem to be loading the language specific resources folder/file, only the common file. I tested with having it display the variable, and sure enough, the variable doesn't update when switching to the alternate language. Do I need to initialize/call out the language specific folder in some way?

  • The issue is, for some reason my app doesn't seem to be loading the language specific resources folder/file, only the common file. I

    Language specific resource folders only work for string resources. If you want to have a different font for each language, you need to write code to select the font based on language.

    The original way to do this would be to use a string resource that is language-specific to identify the language (or font) and then use that string to select a resource for loading. For example:

    var languageName = WatchUi.loadResource(Rez.Strings.Language);
    
    var fontSymbol = null;
    if ("eng".equals(languageName)) {
        fontSymbol = :EnglishFont;
    } else if ("deu".equals(languageName)) {
        fontSymbol = :GermanFont;
    }
    
    var font = Graphics.FONT_TINY;
    if (fontSymbol != null) {
        font = WatchUi.loadResource(Rez.Fonts[fontSymbol]);
    }

    If you are targeting devices with 3.1.0 support, there is a field in DeviceSettings that will allow you to avoid the resource trick part of the above code:

    var deviceSettings = System.getDeviceSettings();
    
    var languageId = deviceSettings.systemLanguage;
    
    var fontSymbol = null;
    if (System.LANGUAGE_ENG == languageId)) {
        fontSymbol = :EnglishFont;
    } else if (System.LANGUAGE_DEU == languageId) {
        fontSymbol = :GermanFont;
    }
    
    var font = Graphics.FONT_TINY;
    if (fontSymbol != null) {
        font = WatchUi.loadResource(Rez.Fonts[fontSymbol]);
    }

  • Thanks for the reply! Sorry, i should have been a little more clear. I am trying to use a string in the language specific folder. Then use that to change a variable, that i use in the view file to select font, kind of like SHN suggested.

    But for some reason the variable in my view file doesn't seem to change to reflect the string value in the language folder, when I change the language in the simulator.

    For example, the string is "0" in my common folder and "1" in my language specific folder. But when I switch languages, it never appears to change from "0" to "1" when it's defined in the view file. Either it never changes or it changes back to "0" before i can display the variable to check the value. 

  • You really need to load up the Strings sample as suggested by  above. It supports a few different languages and we often use it to verify this functionality is working properly.

    If you are using Eclipse, you can click Connect IQ > Samples to find the samples.

  • What I'd probably do is just use the same character set in the fonts.  Say for eng, fre, spa, a-z, A-Z, and the few extra chars for fre and spa.  Use resource overrides for the display to allow for different heights - you'd want them to be bigger on a 390x390 device than on a 208x208 device.  Then use the resource overrides for language for the strings themselves.

  • Figured it out. Don't worry, it was a "dumb as a bag of rocks" error. I needed to add the language as supported in the manifest. Doing that, and re-running the simulator, had the system start to read the folder, edit the variable, and change the font as expected.