Skip to content

Commit

Permalink
Add initial localisation support (#260)
Browse files Browse the repository at this point in the history
* Add initial localisation support

* Update example & changelog

* Commit from GitHub Actions (Forui Presubmit)

* Update docs/pages/docs/localization.mdx

Co-authored-by: Joe Kawai <[email protected]>

* Add missing _meta entry

* Tidy up docs

* Tweak tile arrangement

---------

Co-authored-by: Pante <[email protected]>
Co-authored-by: Joe Kawai <[email protected]>
  • Loading branch information
3 people authored Nov 11, 2024
1 parent f9539da commit f1ea5ec
Show file tree
Hide file tree
Showing 218 changed files with 5,355 additions and 38 deletions.
17 changes: 17 additions & 0 deletions .idea/runConfigurations/Generate_Localizations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -340,3 +340,32 @@ the corresponding Dart code.
3. The query parameters to pass to the sample widget.
4. The height of the `<Widget/>` component.
5. `{}` specifies the lines to highlight.

## Updating Localizations

In most cases, you will not need to update localizations. However, if you do, please read
[Internationalizing Flutter apps](https://docs.flutter.dev/ui/accessibility-and-internationalization/internationalization).
before continuing.

Each ARB file in the `lib/l10n` represents a localization for a specific language. We try to maintain parity with the
languages Flutter natively supports. To add a missing language, run the `fetch_arb` script in the `tool` directory.

After adding the necessary localization messages, run the following command in the `forui` project directory which will
generate the localization files in `lib/src/localizations`:
```shell
flutter gen-l10n
```

Inside the generated `localizations.dart` file, change:
```dart
static FLocalizations of(BuildContext context) {
return Localizations.of<FLocalizations>(context, FLocalizations);
}
```

To:
```dart
static FLocalizations of(BuildContext context) {
return Localizations.of<FLocalizations>(context, FLocalizations) ?? DefaultLocalizations();
}
```
1 change: 1 addition & 0 deletions docs/pages/docs/_meta.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export default {
index: 'Getting Started',
themes: 'Themes',
localization: 'Localization',
responsive: 'Responsive',
'icon-library': 'Icon Library',
api_reference: {
Expand Down
40 changes: 40 additions & 0 deletions docs/pages/docs/localization.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Localization

Forui supports all 115 languages that Flutter natively does.

To enable localization for Forui widgets, add the `FLocalizations.delegate` in your call to the constructor for `
CupertinoApp`, `MaterialApp`, or `WidgetsApp`. Afterwards, add the locales supported by your application.

```dart {3, 6}
Widget build(BuildContext context) => MaterialApp(
localizationsDelegates: [
FLocalizations.delegate, // Add this line
],
supportedLocales: [
// Add locales supported by your application here.
],
builder: (context, child) => FTheme(
data: FThemes.zinc.light,
child: child!,
),
home: const FScaffold(...),
);
```

The `FLocalizations` class also provides auto-generated `localizationsDelegates` and `supportedLocales` lists. You can use
these instead of providing them manually if your application doesn't have any other localization messages.

```dart {2-3}
Widget build(BuildContext context) => MaterialApp(
localizationsDelegates: FLocalizations.localizationsDelegates,
supportedLocales: FLocalizations.supportedLocales,
builder: (context, child) => FTheme(
data: FThemes.zinc.light,
child: child!,
),
home: const FScaffold(...),
);
```

Please see [Internationalizing Flutter apps](https://docs.flutter.dev/ui/accessibility-and-internationalization/internationalization)
for more information.
2 changes: 1 addition & 1 deletion docs/pages/docs/tile/_meta.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default {
tile: 'Tile',
'tile-group': 'Tile Group',
'select-menu-tile': 'Select Menu Tile',
'select-tile-group': 'Select Tile Group',
'select-menu-tile': 'Select Menu Tile',
};
6 changes: 6 additions & 0 deletions forui/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## 0.7.0 (Next)

This update introduces several new tile widgets. It also adds support for responsive breakpoints and localization.

### Additions

* Add `FButtonSpinner`.
Expand Down Expand Up @@ -30,11 +32,15 @@

* Add `FPortal.offset`.

* Add `FLocalizations`.

### Changes

* **Breaking** Change `FPopover()` to not automatically wrap a target in a `GestureDetector` - use `FPopover.tappable(...)`
instead.

* Change `FCalendar` to support localization.

### Fixes

* Change FButton's animation to only start on mouse down and up.
Expand Down
2 changes: 2 additions & 0 deletions forui/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class _ApplicationState extends State<Application> with SingleTickerProviderStat

@override
Widget build(BuildContext context) => MaterialApp(
localizationsDelegates: FLocalizations.localizationsDelegates,
supportedLocales: FLocalizations.supportedLocales,
builder: (context, child) => FTheme(
data: FThemes.zinc.light,
child: child!,
Expand Down
2 changes: 1 addition & 1 deletion forui/example/lib/sandbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class _SandboxState extends State<Sandbox> with SingleTickerProviderStateMixin {
_formKey.currentState!.save();
// Do something.
},
),
)
],
),
);
Expand Down
2 changes: 1 addition & 1 deletion forui/example/macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 236401fc2c932af29a9fcf0e97baeeb2d750d367

COCOAPODS: 1.15.2
COCOAPODS: 1.16.2
28 changes: 14 additions & 14 deletions forui/example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ packages:
dependency: transitive
description:
name: code_builder
sha256: f692079e25e7869c14132d39f223f8eec9830eb76131925143b2129c4bb01b37
sha256: "0ec10bf4a89e4c613960bf1e8b42c64127021740fb21640c29c909826a5eea3e"
url: "https://pub.dev"
source: hosted
version: "4.10.0"
version: "4.10.1"
collection:
dependency: transitive
description:
Expand Down Expand Up @@ -236,10 +236,10 @@ packages:
dependency: transitive
description:
name: flutter_svg
sha256: "7b4ca6cf3304575fe9c8ec64813c8d02ee41d2afe60bcfe0678bcb5375d596a2"
sha256: de82e6bf958cec7190fbc1c5298282c851228e35ae2b14e2b103e7f777818c64
url: "https://pub.dev"
source: hosted
version: "2.0.10+1"
version: "2.0.13"
flutter_test:
dependency: "direct dev"
description: flutter
Expand Down Expand Up @@ -485,18 +485,18 @@ packages:
dependency: transitive
description:
name: path_parsing
sha256: e3e67b1629e6f7e8100b367d3db6ba6af4b1f0bb80f64db18ef1fbabd2fa9ccf
sha256: "883402936929eac138ee0a45da5b0f2c80f89913e6dc3bf77eb65b84b409c6ca"
url: "https://pub.dev"
source: hosted
version: "1.0.1"
version: "1.1.0"
path_provider:
dependency: transitive
description:
name: path_provider
sha256: fec0d61223fba3154d87759e3cc27fe2c8dc498f6386c6d6fc80d1afdd1bf378
sha256: "50c5dd5b6e1aaf6fb3a78b33f6aa3afca52bf903a8a5298f53101fdaee55bbcd"
url: "https://pub.dev"
source: hosted
version: "2.1.4"
version: "2.1.5"
path_provider_android:
dependency: transitive
description:
Expand Down Expand Up @@ -698,26 +698,26 @@ packages:
dependency: transitive
description:
name: vector_graphics
sha256: "32c3c684e02f9bc0afb0ae0aa653337a2fe022e8ab064bcd7ffda27a74e288e3"
sha256: "773c9522d66d523e1c7b25dfb95cc91c26a1e17b107039cfe147285e92de7878"
url: "https://pub.dev"
source: hosted
version: "1.1.11+1"
version: "1.1.14"
vector_graphics_codec:
dependency: transitive
description:
name: vector_graphics_codec
sha256: c86987475f162fadff579e7320c7ddda04cd2fdeffbe1129227a85d9ac9e03da
sha256: "2430b973a4ca3c4dbc9999b62b8c719a160100dcbae5c819bae0cacce32c9cdb"
url: "https://pub.dev"
source: hosted
version: "1.1.11+1"
version: "1.1.12"
vector_graphics_compiler:
dependency: transitive
description:
name: vector_graphics_compiler
sha256: "12faff3f73b1741a36ca7e31b292ddeb629af819ca9efe9953b70bd63fc8cd81"
sha256: "26d520739b7c6b5d2a2b3274427874a8390831fd4cd5bb8cfbd7d913477d3a2e"
url: "https://pub.dev"
source: hosted
version: "1.1.11+1"
version: "1.1.14"
vector_math:
dependency: transitive
description:
Expand Down
7 changes: 7 additions & 0 deletions forui/l10n.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
arb-dir: lib/l10n
template-arb-file: f_en.arb
synthetic-package: false
output-dir: lib/src/localizations
output-localization-file: localizations.dart
output-class: FLocalizations
nullable-getter: false
1 change: 1 addition & 0 deletions forui/lib/forui.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ library forui;

export 'assets.dart';
export 'foundation.dart';
export 'localizations.dart';
export 'theme.dart';

export 'widgets/accordion.dart';
Expand Down
1 change: 1 addition & 0 deletions forui/lib/l10n/f_af.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions forui/lib/l10n/f_am.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions forui/lib/l10n/f_ar.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions forui/lib/l10n/f_as.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions forui/lib/l10n/f_az.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions forui/lib/l10n/f_be.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions forui/lib/l10n/f_bg.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions forui/lib/l10n/f_bn.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions forui/lib/l10n/f_bs.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions forui/lib/l10n/f_ca.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions forui/lib/l10n/f_cs.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions forui/lib/l10n/f_cy.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions forui/lib/l10n/f_da.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions forui/lib/l10n/f_de.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions forui/lib/l10n/f_de_CH.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions forui/lib/l10n/f_el.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
56 changes: 56 additions & 0 deletions forui/lib/l10n/f_en.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"fullDate": "{date}",
"@fullDate": {
"description": "The full date.",
"placeholders": {
"date": {
"type": "DateTime",
"format": "yMMMMd"
}
}
},

"year": "{date}",
"@year": {
"description": "The year.",
"placeholders": {
"date": {
"type": "DateTime",
"format": "y"
}
}
},

"yearMonth": "{date}",
"@yearMonth": {
"description": "The year and month.",
"placeholders": {
"date": {
"type": "DateTime",
"format": "yMMMM"
}
}
},

"abbreviatedMonth": "{date}",
"@abbreviatedMonth": {
"description": "The abbreviated month.",
"placeholders": {
"date": {
"type": "DateTime",
"format": "MMM"
}
}
},

"day": "{date}",
"@day": {
"description": "The day of the month.",
"placeholders": {
"date": {
"type": "DateTime",
"format": "d"
}
}
}
}
1 change: 1 addition & 0 deletions forui/lib/l10n/f_en_AU.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions forui/lib/l10n/f_en_CA.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions forui/lib/l10n/f_en_GB.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions forui/lib/l10n/f_en_IE.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions forui/lib/l10n/f_en_IN.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions forui/lib/l10n/f_en_NZ.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions forui/lib/l10n/f_en_SG.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions forui/lib/l10n/f_en_ZA.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions forui/lib/l10n/f_es.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions forui/lib/l10n/f_es_419.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Loading

0 comments on commit f1ea5ec

Please sign in to comment.