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

Issue when generating multiple arbs #3

Open
k-ane opened this issue May 4, 2023 · 3 comments
Open

Issue when generating multiple arbs #3

k-ane opened this issue May 4, 2023 · 3 comments

Comments

@k-ane
Copy link

k-ane commented May 4, 2023

I am generating multiple arb files (like the example) and for the most part it's working great. I am mainly doing this to be able to split up my translations by feature, which is very cool that it works.

The issue is that if two features have a 'title', that to prevent conflicts I have to prefix the message name with the class name. I'll include an example of the code here:

@GenerateArb(suppressLastModified: true, dir: 'assets/arb')
class DashboardTranslations {
  static DashboardTranslations of(BuildContext context) =>
      Localizations.of<DashboardTranslations>(context, DashboardTranslations)!;

  String get title => Intl.message(
        'Dashboard title',
        name: 'DashboardTranslations_title',
      );

  String get hero => Intl.message(
        'Build your next idea even faster.',
        name: 'DashboardTranslations_hero',
      );
}

This does work as expected, the problem is having to type out DashboardTranslations_ for each name, as it's tedious and harder to read.

I'm wondering if we can have an option under GenerateArb to prefix all names with the class name? Perhaps like this:

@GenerateArb(suppressLastModified: true, dir: 'assets/arb', prefixMessageNames: true)
class DashboardTranslations {

That way my message could look like this:

  String get title => Intl.message(
        'Dashboard title',
        name: 'title',
  );

This would produce arb like so:

{
  "@@locale": "en",
  "DashboardTranslations_title": "Dashboard title",
  "@DashboardTranslations_title": {
    "type": "text",
    "placeholders_order": [],
    "placeholders": {}
  },
  "DashboardTranslations_hero": "Build your next idea even faster.",
  "@DashboardTranslations_hero": {
    "type": "text",
    "placeholders_order": [],
    "placeholders": {}
  }
}

Lastly it would be even better again if I could omit the name and end up with the same arb. The name is pretty much always the same as the getter. I don't know if it would be possible but I would love to write this:

String get title => Intl.message('Dashboard title');

Thank you so much @jaumard for the work you've done on this package by the way, even without the fixes above it's a huge improvement over having one massive file.

@jaumard
Copy link
Owner

jaumard commented May 8, 2023

Hello @k-ane
Thanks for your feedback, indeed keys should not contains duplicates as all sentence are loaded into a Map.

I would prefer something like this:

@GenerateArb(suppressLastModified: true, dir: 'assets/arb', prefix: 'MyPrefix')

That would let people choose what they want, example if the class name is too long it might not be wanted (even more if you download ARB from the network as it will make it heavier). I didn't check yet but that should be doable!

Lastly it would be even better again if I could omit the name and end up with the same arb. The name is pretty much always the same as the getter. I don't know if it would be possible but I would love to write this:
String get title => Intl.message('Dashboard title');

Unfortunately that's not doable, the way Intl is working make it impossible to not have this I think from memory.

@k-ane
Copy link
Author

k-ane commented May 9, 2023

Thanks for your reply @jaumard, that seems like a good solution to me!

Understandable on the second point, it's not a big deal to have to provide a name anyway😊

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

3 participants
@jaumard @k-ane and others