Greg Spencer | ca71355 | 2020-06-30 09:15:04 -0700 | [diff] [blame^] | 1 | # Flutter Framework localizations |
| 2 | |
| 3 | This package contains the localizations used by the Flutter framework |
| 4 | itself. |
| 5 | |
| 6 | See the [localization README](./lib/src/README.md) for more detailed |
| 7 | information about the localizations themselves. |
| 8 | |
| 9 | ## Adding a new string to localizations |
| 10 | |
| 11 | If you (someone contributing to the Flutter framework) want to add a new |
| 12 | string to the `MaterialLocalizations`, `WidgetsLocalizations` or the |
| 13 | `CupertinoLocalizations` objects (e.g. because you've added a new widget |
| 14 | and it has a tooltip), follow these steps (these instructions are for |
| 15 | `MaterialLocalizations`, but apply equally to `CupertinoLocalizations` |
| 16 | and `WidgetsLocalizations`, with appropriate name substitutions): |
| 17 | |
| 18 | 1. Add the new getter to the localizations class `MaterialLocalizations`, |
| 19 | in `flutter_localizations/lib/src/material_localizations.dart`. |
| 20 | |
| 21 | 2. Implement a default value in `DefaultMaterialLocalizations` in |
| 22 | `flutter_localizations/lib/src/material_localizations.dart` |
| 23 | |
| 24 | 3. Add a test to `test/material/localizations_test.dart` that verifies that |
| 25 | this new value is implemented. |
| 26 | |
| 27 | 4. Update the `flutter_localizations` package. To add a new string to the |
| 28 | `flutter_localizations` package, you must first add it to the English |
| 29 | translations (`lib/src/l10n/material_en.arb`), including a description. |
| 30 | |
| 31 | Then you need to add new entries for the string to all of the other |
| 32 | language locale files by running: |
| 33 | ``` |
| 34 | dart dev/tools/localization/bin/gen_missing_localizations.dart |
| 35 | ``` |
| 36 | Which will copy the english strings into the other locales as placeholders |
| 37 | until they can be translated. |
| 38 | |
| 39 | Finally you need to re-generate lib/src/l10n/localizations.dart by running: |
| 40 | ``` |
| 41 | dart dev/tools/localization/bin/gen_localizations.dart --overwrite |
| 42 | ``` |
| 43 | |
| 44 | There is a [localization README](./lib/src/README.md) file with further |
| 45 | information in the `lib/src/l10n/` directory. |
| 46 | |
| 47 | 5. If you are a Google employee, you should then also follow the instructions |
| 48 | at `go/flutter-l10n`. If you're not, don't worry about it. |
| 49 | |
| 50 | ## Updating an existing string |
| 51 | |
| 52 | If you or someone contributing to the Flutter framework wants to modify an |
| 53 | existing string in the MaterialLocalizations objects, follow these steps: |
| 54 | |
| 55 | 1. Modify the default value of the relevant getter(s) in |
| 56 | `DefaultMaterialLocalizations` below. |
| 57 | |
| 58 | 2. Update the `flutter_localizations` package. Modify the out-of-date English |
| 59 | strings in `lib/src/l10n/material_en.arb`. |
| 60 | |
| 61 | You also need to re-generate `lib/src/l10n/localizations.dart` by running: |
| 62 | ``` |
| 63 | dart dev/tools/localization/bin/gen_localizations.dart --overwrite |
| 64 | ``` |
| 65 | |
| 66 | This script may result in your updated getters being created in newer |
| 67 | locales and set to the old value of the strings. This is to be expected. |
| 68 | Leave them as they were generated, and they will be picked up for |
| 69 | translation. |
| 70 | |
| 71 | There is a [localization README](./lib/src/README.md) file with further |
| 72 | information in the `lib/src/l10n/` directory. |
| 73 | |
| 74 | 3. If you are a Google employee, you should then also follow the instructions |
| 75 | at `go/flutter-l10n`. If you're not, don't worry about it. |