slang-i18n / slang

Type-safe i18n for Dart and Flutter
https://pub.dev/packages/slang
MIT License
419 stars 36 forks source link

enum's not generated for base_locale_empty_string #182

Closed yagmure15 closed 5 months ago

yagmure15 commented 6 months ago

Describe the bug I would like to sincerely thank you for the development of base_locale_empty_string. Here, I have made the necessary additions in the English JSON file. I'm also adding other languages as 'empty' just like in the examples. This way, the person doing the translations understands that they need to translate it. When I initially send the section parts like in the first example, there's no problem. However, when the translator translates some parts and not others in the second example, it becomes an issue.

Example 1 strings_en.i18n.json

    "sections(context=Sections, param=sections)": {
      "deviceInfo": "Device Info",
      "identification": "Identification",
      "information": "Information",
      "notes": "Notes",
      "purchaseInfo": "Purchase Info"
    },

strings_ro.i18n.json

    "sections(context=Sections, param=sections)": {
      "deviceInfo": "",
      "identification": "",
      "information": "",
      "notes": "",
      "purchaseInfo": ""
    },

Example 2 strings_en.i18n.json

    "sections(context=Sections, param=sections)": {
      "deviceInfo": "Device Info",
      "identification": "Identification",
      "information": "Information",
      "notes": "Notes",
      "purchaseInfo": "Purchase Info"
    },

strings_ro.i18n.json

    "sections(context=Sections, param=sections)": {
      "deviceInfo": "Informații dispozitiv",
      "identification": "Identificare",
      "information": "",
      "notes": "notes",
      "purchaseInfo": "Informații achiziție"
    },

Error Message Failed to build iOS app Error (Xcode): lib/translations/strings.g.dart:3819:11: Error: The type 'Sections' is not exhaustively matched by the switch cases since it doesn't match 'Sections.information'.

Tienisto commented 6 months ago

You will need to remove the whole context node. Currently, each language is generated separately from each other, so "ro" does not know what strings in "en" exist.

Another issue is that fallback works by using the extension behavior of Dart classes. There is currently no easy way to represent inheritance within a function.

yagmure15 commented 6 months ago

The context node is very useful for us; the slang library is one of the reasons we prefer it. Otherwise, the code becomes more complicated. The likelihood of encountering the situation in the second example is very high, and in that case, the application crashes. At the very least, to prevent the application from crashing, a default "" (empty string) can be provided in the string.g.dart file.

string.g.dart file

.
.
.
  @override
  String sections({required Sections sections}) {
    switch (sections) {
      case Sections.deviceInfo:
        return 'Informații dispozitiv';
      case Sections.identification:
        return 'Identificare';
      case Sections.notes:
        return 'Note';
      case Sections.purchaseInfo:
        return 'Informații achiziție';
      default:
         return '';
    }
  }
.
.
.

Even in this case, I will have to find the empty value in the generated files and process it. I am considering replacing "" (the empty values) with an expression like "untranslated key -> $keyvalue." That's the general situation. What do you think? Is there another way?

talhakerpicci commented 5 months ago

Im having the same issue. Any plans on handling this case?

Tienisto commented 5 months ago

Fixed in v3.29.0