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] Optionally generate list of inputs/outputs #56490

Merged
merged 14 commits into from May 7, 2020

Conversation

shihaohong
Copy link
Contributor

Description

This PR creates a new option to output a list of inputs and outputs for the gen_l10n tool. It takes in the path (either relative or absolute) and creates an gen_l10n_inputs_and_outputs.json file. Using this option for the stocks app example, here is a sample output:

{
  "inputs": [
    "absolute/path/to/app/stocks/lib/i18n/stocks_en.arb",
    "absolute/path/to/app/stocks/lib/i18n/stocks_en_US.arb",
    "absolute/path/to/app/stocks/lib/i18n/stocks_es.arb"
  ],
  "outputs": [
    "absolute/path/to/app/stocks/lib/i18n/stock_strings_en.dart",
    "absolute/path/to/app/stocks/lib/i18n/stock_strings_es.dart",
    "absolute/path/to/app/stocks/lib/i18n/stock_strings.dart"
  ]
}

The PR also gratuitously fixes up terminology and tests that could be improved surrounding writeOutputFile and generateCode. These updates should not be breaking, since the developer API has not been modified.

Related Issues

Fixes #55503

Tests

I added the following tests:

  • Adds a test to ensure that the json file is produced at the path specified
  • Modifies existing tests to call writeOutputFile() instead of generateCode(), since generateCode has become an implementation of writeOutputFile
  • Modified writeOutputFile to plural writeOutputFiles since the tool now generates more than one localization file (it has been generating more than one file prior to this PR, but the code hasn't been updated so it was confusing).

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read Handling breaking changes.

  • No, no existing tests failed, so this is not a breaking change.
  • Yes, this is a breaking change. If not, delete the remainder of this section.
    • I wrote a design doc: https://flutter.dev/go/template Replace this with a link to your design doc's short link
    • I got input from the developer relations team, specifically from: Replace with the names of who gave advice
    • I wrote a migration guide: Replace with a link to your migration guide

@shihaohong shihaohong added tool Affects the "flutter" command-line tool. See also t: labels. a: internationalization Supporting other languages or locales. (aka i18n) labels May 6, 2020
}
_inputsAndOutputsListFile.writeAsStringSync(
inputAndOutputsJsonFileTemplate
.replaceAll('@(inputs)', _inputFileList.map((String file) => '"$file"').join(',\n '))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using string replace, create a map and use json.encode:

_inputsAndOutputsListFile.writeAsStringSync(
  json.encode(<String, Object>{
    'inputs': _inputFileList,
    'outputs': _outputFileList,
  }),
)

Copy link
Member

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@HansMuller HansMuller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM too, modulo a few trivial wording issues

'gen-inputs-and-outputs-list',
valueHelp: 'path-to-output-directory',
help: 'When specified, the tool generates a JSON file containing the '
'tool\'s inputs and outputs titled gen_l10n_inputs_and_outputs.json.'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

titled => named

'project were used when generating the latest set of localizations. '
'For example, the Flutter tool\'s build system uses this file to '
'keep track of when to call gen_l10n during hot reload.\n\n'
'This option takes in the directory where the JSON file will be '
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value of this option is the directory...

@fluttergithubbot fluttergithubbot merged commit 13501af into flutter:master May 7, 2020
@shihaohong shihaohong deleted the gen_l10n_input_output branch May 14, 2020 00:37
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 31, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a: internationalization Supporting other languages or locales. (aka i18n) tool Affects the "flutter" command-line tool. See also t: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[gen_l10n] Tool should output files that were read and written
5 participants