Package problem

While android previewing the app , this error shows up:
C:\Users\USER\Documents\GitHub\MyIQFinanceMobile\DeviceLocale.uno(30,24): Error E3107: ‘Language’ does not contain a member called ‘Java’. Could you be missing a package reference

And this is DeviceLocale.uno code:

using Uno;
using Uno.UX;
using Uno.Text;
using Uno.Collections;
using Uno.Compiler.ExportTargetInterop;
using Fuse;
using Fuse.Scripting;
using Fuse.Reactive;
[extern(Android)ForeignInclude(Language.Java, “android.app.Activity”, “android.provider.Settings”,
“android.content.","java.security.”, “java.util.regex.", "java.util.”,
java.net.", "java.nio.”, “java.io.*”)]

[extern(iOS) ForeignInclude(Language.ObjC, “sys/types.h”, “sys/sysctl.h”)]

[UXGlobalModule]
public sealed class DeviceLocale : NativeModule {
static readonly DeviceLocale _instance;

public DeviceLocale() : base() {
    if (_instance != null) return;
    Uno.UX.Resource.SetGlobalKey(_instance = this, "DeviceLocale");

    AddMember(new NativeProperty< string, object >("locale", GetCurrentLocale));
}


[Foreign(Language.Java)]
public static extern(Android) string GetCurrentLocale()
@{
	Locale loc = java.util.Locale.getDefault();

    final char separator = '-';
    String language = loc.getLanguage();
    String region   = loc.getCountry();
    String variant  = loc.getVariant();

    // special case for Norwegian Nynorsk since "NY" cannot be a variant as per BCP 47
    // this goes before the string matching since "NY" wont pass the variant checks
    if (language.equals("no") && region.equals("NO") && variant.equals("NY")) {
        language = "nn";
        region   = "NO";
        variant  = "";
    }

    if (language.isEmpty() || !language.matches("\\p{Alpha}{2,8}")) {
        language = "und"; // "und" for Undetermined
    } else if (language.equals("iw")) {
        language = "he";  // correct deprecated "Hebrew"
    } else if (language.equals("in")) {
        language = "id";  // correct deprecated "Indonesian"
    } else if (language.equals("ji")) {
        language = "yi";   // correct deprecated "Yiddish"
    }

    // ensure valid country code, if not well formed, it's omitted
    if (!region.matches("\\p{Alpha}{2}|\\p{Digit}{3}")) {
        region = "";
    }

     // variant subtags that begin with a letter must be at least 5 characters long
    if (!variant.matches("\\p{Alnum}{5,8}|\\p{Digit}\\p{Alnum}{3}")) {
        variant = "";
    }

    StringBuilder bcp47Tag = new StringBuilder(language);
    if (!region.isEmpty()) {
        bcp47Tag.append(separator).append(region);
    }

    if (!variant.isEmpty()) {
        bcp47Tag.append(separator).append(variant);
    }

    return bcp47Tag.toString();
@}

[Foreign(Language.ObjC)]
private static extern(iOS) string GetCurrentLocale()
@{
	NSString* language = NSLocale.preferredLanguages[0];

    if (language.length <= 2) {
        NSLocale* locale        = NSLocale.currentLocale;
        NSString* localeId      = locale.localeIdentifier;
        NSRange underscoreIndex = [localeId rangeOfString: @"_" options: NSBackwardsSearch];
        NSRange atSignIndex     = [localeId rangeOfString: @"@"];

        if (underscoreIndex.location != NSNotFound) {
            if (atSignIndex.length == 0)
                language = [NSString stringWithFormat: @"%@%@", language, [localeId substringFromIndex: underscoreIndex.location]];
            else {
                NSRange localeRange = NSMakeRange(underscoreIndex.location, atSignIndex.location - underscoreIndex.location);
                language = [NSString stringWithFormat: @"%@%@", language, [localeId substringWithRange: localeRange]];
            }
        }
    }

    return [language stringByReplacingOccurrencesOfString: @"_" withString: @"-"];
@}

// Preview's implementations
public static extern(!Mobile) string GetCurrentLocale() {
	return "en-EN";
}

}

Is it problem with the packages?Should I use something like
using Language; ???

It’s okay , I solved it by myself. :slight_smile:
I just deleted this uno and all binding with it.(JS).
You should check the DeviceLocale.uno that You have on your repo.It has bugs with the Language package.

Which version of Fuse did you test this with?

I assume the code comes from this repo?

I just tested it with Fuse 1.7.0 and there it worked just as expected for both Android preview and Android export.

I am using 1.5.0v , and as I understood the code , correct me if I’m wrong but the device.uno file is not needed.I deleted it and in the localization.js i commented this line:

setLocale(DeviceLocale.locale);

The thing is every label that I need to translate I write it in the .json files (in this ex. en-US and the others, with the KEY and the VALUE that goes along with it) and I call the localization.js in every page’s JS.It works like a charm.

What do you think , is it correct to do that ( delete the device.uno)?

Cheers.

device.uno has never been part of the https://github.com/drslem/fuse-localization repo, so it is definitely not required if you just want the localization stuff. :slight_smile:

than why is DeviceLocale.uno called in localization.js?

unoproj code:

“Includes”: [
",
“DeviceLocale.uno”, <–
“Localization.js:Bundle”,
"text/
.json:Bundle”
]

localization.js:

var Observable = require(“FuseJS/Observable”);
var Bundle = require(“FuseJS/Bundle”);
var DeviceLocale = require(“DeviceLocale”); <-
loc = Observable();

var Locales = { “default”: “en-US.json”,
“en-US”: “en-US.json”,
“en-GB”: “en-GB.json”,
“nb-NO”: “nb-NO.json”
};

function setLocale(locale){
if(locale in Locales) f = Locales[locale];
else f = Locales[“default”];
loc.value = JSON.parse(Bundle.readSync(“text/”+f));
}

setLocale(DeviceLocale.locale); <-

module.exports = {loc, setLocale};

DeviceLocale.uno belongs in the project. device.uno does not.

It was device.uno that you mentioned in your previous post:

What do you think , is it correct to do that ( delete the device.uno)?

But if you do not need to check which language the device uses (e.g. you don’t want to automatically give the user the language they’ve set on their phone) then you don’t need DeviceLocale.uno either. :slight_smile: