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

[gen_l10n] Document messages with translations for supported locales #67206

Closed
szotp opened this issue Oct 3, 2020 · 8 comments
Closed

[gen_l10n] Document messages with translations for supported locales #67206

szotp opened this issue Oct 3, 2020 · 8 comments

Comments

@szotp
Copy link

@szotp szotp commented Oct 3, 2020

Consider this localization file:

{
    "@@locale": "en",
    "@@last_modified": "2020-10-03T09:49:55.929624",
    "helloThere": "Hello there {name}",
    "@helloThere": {
        "placeholders": {
            "name": {}
        },
        "description": "Lorem ipsum...",
        "type": "text"
    },
}

It will generate this property:

// Lorem ipsum...
String heloThere(Object arg0);

But it would be much nicer if it also added documentation comment with translations:

/// en: Hello there {name}
/// Lorem ipsum...
/// de: !!! translation missing !!!
/// pl: No elo {name}
String heloThere(Object arg0);

This way, IDE will guide you as your are writing widgets, and you can now easily find missing translations with search functions.

@shihaohong Does this sound good? If yes, I could try to implement this and submit PR

Related ticket: #41437

@szotp
Copy link
Author

@szotp szotp commented Oct 3, 2020

Also, current @comment logic does not handle new lines. On one hand, it's a bug, on the other hand, I can use it to insert the documentation I want here.

@jmagman jmagman added this to Awaiting triage in Tools - framework support review via automation Oct 6, 2020
@christopherfujino christopherfujino moved this from Awaiting triage to Engineer reviewed in Tools - framework support review Oct 6, 2020
@christopherfujino
Copy link
Contributor

@christopherfujino christopherfujino commented Oct 6, 2020

@shihaohong could you take a look?

@shihaohong
Copy link
Contributor

@shihaohong shihaohong commented Oct 19, 2020

I like the idea in concept, but applications that support a larger number of translations would have a massive number of comments. For example, the gallery supports dozens of locales and the comments for each message would be extremely long if we wanted to document every single translation for each message.

To clarify -- Is the issue here difficulty in figuring which translations are missing? There's an option called --untranslated-messages-file that helps list out the messages that are missing translations and for which locales.

@shihaohong shihaohong changed the title [gen_l10n] add documentation comments [gen_l10n] Document messages with translations for supported locales Oct 19, 2020
@szotp
Copy link
Author

@szotp szotp commented Oct 19, 2020

Good point. For me the most common case is two supported languages (english + developer's native language), so putting all translations there made sense.

So instead we could put only template language + info for missing translations + maybe some docs about placeholders.

This issue is not really about untranslated messages, I just mentioned it as it seemed nice to have. Actual issue is about having clear information about given localization string without looking up the .arb file or generated code. When writing widgets it's not always clear which text will be used.

BTW, I'm aware of --untranslated-messages-file it's printed every time I'm running the app, but I don't really know which command to use. flutter pub get --untranslated-messages-file x.txt doesn't work.

@shihaohong
Copy link
Contributor

@shihaohong shihaohong commented Oct 20, 2020

Actually, that's a bug and has been printing incorrectly. I just submitted #68553 which should fix that issue.

I believe the issue you're facing here is that you're using --untranslated-messages-file correctly, but since you have all translations completed, the file is just not generating. I've made an adjustment in the same PR that causes the tool to generate an empty JSON instead of not doing anything in the event that all messages for every locale have existing translations.

@szotp
Copy link
Author

@szotp szotp commented Oct 26, 2020

Cool. Then this ticket is mostly about adding some comment docs, could be as simple as:

/// en: Hello there {name}
String helloThere(Object arg0);
@shihaohong
Copy link
Contributor

@shihaohong shihaohong commented Oct 26, 2020

I'll take a look into what we can do to make the docs helpful without cluttering it with too much noise. Maybe I'll start with the simple string getters first as a start and iterate to address the more complex ones, like methods with placeholders.

@shihaohong
Copy link
Contributor

@shihaohong shihaohong commented Oct 26, 2020

@szotp I created a PR that adds a new comment line with the message value in the template arb locale. Take a look and provide any feedback if you have any!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Tools - framework support review
  
Engineer reviewed
Linked pull requests

Successfully merging a pull request may close this issue.

5 participants
You can’t perform that action at this time.