slang-i18n / slang

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

LocaleSettings.overrideTranslationsFromMap Fails with Nested Map Structure #242

Closed ZakariasBW closed 1 month ago

ZakariasBW commented 1 month ago

Describe the bug LocaleSettings.overrideTranslationsFromMap fails when provided with a nested map structure that does not include keys at the top level.

To Reproduce

  1. For this strings.i18n.json
    {
    "customerService": {
    "title": "Customer support",
    "other": {
      "title": "Other"
    }
    }
    }
  2. Run this test, and note that it fails with type 'ObjectNode' is not a subtype of type 'StringTextNode' in type cast
    test('Broken', () {
    LocaleSettings.overrideTranslationsFromMap(
    locale: AppLocale.en,
    isFlatMap: false,
    map: {
      "customerService": {
        "other": {
          "title": "Test",
        }
      }
    },
    );
    });
  3. While this test does not:
    test('Working', () {
    LocaleSettings.overrideTranslationsFromMap(
    locale: AppLocale.en,
    isFlatMap: false,
    map: {
      "customerService": {
        "title": "Customer support",
        "other": {
          "title": "Test",
        }
      }
    },
    );
    });

Expected behavior The field t.customerService.other.title should have value Test in both cases.

Additional context Slang version for testing is ^3.31.1 with no special slang.yaml config except of course translation_overrides: true.

Tienisto commented 1 month ago

I believe that customerService is wrongly inferred as plural. Can you try to set:

pluralization:
  auto: off
ZakariasBW commented 1 month ago

Thank you so much for the quick reply🙏, it worked! We didn't think of that😅