Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There are no translations in 'en_' for key #1

Closed
IchordeDionysos opened this issue Oct 26, 2019 · 3 comments
Closed

There are no translations in 'en_' for key #1

IchordeDionysos opened this issue Oct 26, 2019 · 3 comments

Comments

@IchordeDionysos
Copy link

The locale en_ does not get mapped onto en locale.

So when the local is en_, then with the translations from below it will throw the error:

➜ There are no translations in 'en_' for "not_found".

import 'package:i18n_extension/i18n_extension.dart';

extension Localization on String {

  static var t = Translations.byLocale("de") +
      {
        "en": {
          "not_found": "404 not found",
        },
        "de": {
          "not_found": "404 nicht gefunden",
        },
      };

  String get i18n => localize(this, t);
}
@marcglasberg
Copy link
Owner

marcglasberg commented Oct 27, 2019

Ok, I can remove the _ and turn en_ into en. Easy fix, but, a question: isn't en_ a malformed Locale? Do you know the link to the Locale specification?

@IchordeDionysos
Copy link
Author

@marcglasberg I did some research 🤔
In the dart documentation the method Locale.toString() they say:

it is intended to be used for debugging purposes only. For parseable results, use toLanguageTag instead.

However, in this package locale.toString() is used.

I was not sure if this was the problem so I did some debugging and found out that:
Locale("en") is okay and will output "en",
Locale("en", "") is not okay and will output "en_", ...

A bit more info: This happens on my iOS Simulator 🤔

As this seems to be at the root a Flutter issue, I opened one over there.
flutter/flutter#43607

@marcglasberg
Copy link
Owner

In any case it now removes extra spaces and "_", so this should be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants