Skip to content

Commit

Permalink
Merge branch 'main' into addCollationICU4X
Browse files Browse the repository at this point in the history
  • Loading branch information
mosuem authored Jan 11, 2024
2 parents 2d40719 + 6a12365 commit f36d1cf
Show file tree
Hide file tree
Showing 46 changed files with 483 additions and 471 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ jobs:
strategy:
matrix:
sdk: [stable, dev] # {pkgs.versions}
dependencies: [path, published]
include:
- sdk: stable
run-tests: true

steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9
- uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d
Expand Down
4 changes: 4 additions & 0 deletions pkgs/intl4x/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.7.1

- Export plural rules.

## 0.7.0

- Add conformance testing workflow.
Expand Down
1 change: 1 addition & 0 deletions pkgs/intl4x/lib/intl4x.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import 'src/plural_rules/plural_rules_impl.dart';
import 'src/plural_rules/plural_rules_options.dart';

export 'src/locale/locale.dart';
export 'src/plural_rules/plural_rules.dart';

typedef Icu4xKey = String;

Expand Down
2 changes: 1 addition & 1 deletion pkgs/intl4x/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: intl4x
description: >-
A lightweight modular library for internationalization (i18n) functionality.
version: 0.7.0
version: 0.7.1
repository: https://github.com/dart-lang/i18n/tree/main/pkgs/intl4x
platforms: ## TODO: Add native platforms once ICU4X is integrated.
web:
Expand Down
3 changes: 2 additions & 1 deletion pkgs/intl_translation/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
## 0.19.0-wip
## 0.19.0
* Always generate null safe code, remove `null-safe` flag.
* Add example for `he` locale.
* MessageExtraction: add set of error codes to be ignored in analysis.
* Upgrade dependencies on `analyzer` and `lints`.
* Fix pubspec `repository` url.
* Fix error in `toString` of `Message`s.

## 0.18.1
* Update analyzer dependency to `5.2.0`.
Expand Down
2 changes: 1 addition & 1 deletion pkgs/intl_translation/lib/src/messages/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import 'variable_substitution_message.dart';
const jsonEncoder = JsonCodec();

/// A default function for the [Message.expanded] method.
String nullTransform(dynamic msg, dynamic chunk) => chunk as String;
String nullTransform(dynamic msg, dynamic chunk) => chunk.toString();

/// An abstract superclass for Intl.message/plural/gender calls in the
/// program's source text. We
Expand Down
2 changes: 1 addition & 1 deletion pkgs/intl_translation/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: intl_translation
version: 0.19.0-wip
version: 0.19.0
description: >-
Contains code to deal with internationalized/localized messages,
date and number formatting and parsing, bi-directional text, and
Expand Down
5 changes: 5 additions & 0 deletions pkgs/messages/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.2.0

- Remove `IntlObject` interface.
- Introduce `PluralRules` to retrieve the correct message for plurals.

## 0.1.1

- Update README.
Expand Down
7 changes: 2 additions & 5 deletions pkgs/messages/example_json/bin/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@
import 'dart:io';

import 'package:example_json/testarbctx2.g.dart';
import 'package:messages/package_intl_object.dart';

Future<void> main(List<String> arguments) async {
final messages = AboutPageMessages(
(String id) async => File(id).readAsString(),
const OldIntlObject(),
);
final messages =
AboutPageMessages((String id) async => File(id).readAsString());
// final index = AboutPageMessagesEnum.aboutMessage;

await messages.loadLocale('en');
Expand Down
40 changes: 28 additions & 12 deletions pkgs/messages/example_json/lib/testarb.g.dart
Original file line number Diff line number Diff line change
@@ -1,41 +1,37 @@
// Generated by package:messages_builder
// Generated by package:messages_builder.

import 'package:intl4x/intl4x.dart';
import 'package:messages/messages_json.dart';

class HomePageMessages {
HomePageMessages(
this._fileLoader,
this.intlObject,
);
HomePageMessages(this._fileLoader);

final Future<String> Function(String id) _fileLoader;

String _currentLocale = 'en';

final Map<String, MessageList> _messages = {};

static const carbs = {
static const _dataFiles = {
'de': ('lib/testarb_de.json', 'hbDN1MhX'),
'en': ('lib/testarb.json', 'dr9Md951')
};

IntlObject intlObject;

String get currentLocale => _currentLocale;

MessageList get _currentMessages => _messages[currentLocale]!;

static Iterable<String> get knownLocales => carbs.keys;
static Iterable<String> get knownLocales => _dataFiles.keys;

Future<void> loadLocale(String locale) async {
if (!_messages.containsKey(locale)) {
final info = carbs[locale];
final info = _dataFiles[locale];
final carb = info?.$1;
if (carb == null) {
throw ArgumentError('Locale $locale is not in $knownLocales');
}
final data = await _fileLoader(carb);
final messageList = MessageListJson.fromString(data, intlObject);
final messageList = MessageListJson.fromString(data, pluralSelector);
if (messageList.preamble.hash != info?.$2) {
throw ArgumentError('''
Messages file for locale $locale has different hash "${messageList.preamble.hash}" than generated code "${info?.$2}".''');
Expand All @@ -46,11 +42,31 @@ class HomePageMessages {
}

void loadAllLocales() {
for (var locale in knownLocales) {
for (final locale in knownLocales) {
loadLocale(locale);
}
}

Message pluralSelector(
num howMany, {
required Message other,
Message? few,
Message? many,
Map<int, Message>? numberCases,
Map<int, Message>? wordCases,
}) {
Message getCase(int i) => numberCases?[i] ?? wordCases?[i] ?? other;
return switch (
Intl(locale: Locale.parse(currentLocale)).plural().select(howMany)) {
PluralCategory.zero => getCase(0),
PluralCategory.one => getCase(1),
PluralCategory.two => getCase(2),
PluralCategory.few => few ?? other,
PluralCategory.many => many ?? other,
PluralCategory.other => other,
};
}

String helloAndWelcome(
String firstName,
String lastName,
Expand Down
2 changes: 1 addition & 1 deletion pkgs/messages/example_json/lib/testarb.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[0,"en","dr9Md951",0,null,["Welcome von !",[8,0],[13,1]],["Welcome von !",[8,0],[13,1]],[6,"test ",[3,0,["test new messages",[5,0]],[2,"No new messages",4,"One new message",5,"Two new Messages"]]],[6,"test ",[4,0,"Two new Messages",{"male":"No new messages","female":"One new message"}]]]
[0,"en","dr9Md951",0,null,["Welcome von !",[8,0],[13,1]],["Welcome von !",[8,0],[13,1]],[6,"test ",[3,0,["test new messages",[5,0]],[0,"No new messages",1,"One new message","w2","Two new Messages"]]],[6,"test ",[4,0,"Two new Messages",{"male":"No new messages","female":"One new message"}]]]
2 changes: 1 addition & 1 deletion pkgs/messages/example_json/lib/testarb_de.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[0,"de","hbDN1MhX",0,null,["Willkommen von ",[11,0],[16,1]],["Willkommen von 2",[11,0],[16,1]],[6,"testde ",[3,0,["test new messages",[5,0]],[2,"No new messages",4,"One new message",5,"Two new Messages"]]],"testdse is just a simple message"]
[0,"de","hbDN1MhX",0,null,["Willkommen von ",[11,0],[16,1]],["Willkommen von 2",[11,0],[16,1]],[6,"testde ",[3,0,["test new messages",[5,0]],[0,"No new messages",1,"One new message","w2","Two new Messages"]]],"testdse is just a simple message"]
40 changes: 28 additions & 12 deletions pkgs/messages/example_json/lib/testarbctx2.g.dart
Original file line number Diff line number Diff line change
@@ -1,41 +1,37 @@
// Generated by package:messages_builder
// Generated by package:messages_builder.

import 'package:intl4x/intl4x.dart';
import 'package:messages/messages_json.dart';

class AboutPageMessages {
AboutPageMessages(
this._fileLoader,
this.intlObject,
);
AboutPageMessages(this._fileLoader);

final Future<String> Function(String id) _fileLoader;

String _currentLocale = 'en';

final Map<String, MessageList> _messages = {};

static const carbs = {
static const _dataFiles = {
'fr': ('lib/testarbctx2_fr.json', 'EyPjEJJU'),
'en': ('lib/testarbctx2.json', 'QrwRSsOy')
};

IntlObject intlObject;

String get currentLocale => _currentLocale;

MessageList get _currentMessages => _messages[currentLocale]!;

static Iterable<String> get knownLocales => carbs.keys;
static Iterable<String> get knownLocales => _dataFiles.keys;

Future<void> loadLocale(String locale) async {
if (!_messages.containsKey(locale)) {
final info = carbs[locale];
final info = _dataFiles[locale];
final carb = info?.$1;
if (carb == null) {
throw ArgumentError('Locale $locale is not in $knownLocales');
}
final data = await _fileLoader(carb);
final messageList = MessageListJson.fromString(data, intlObject);
final messageList = MessageListJson.fromString(data, pluralSelector);
if (messageList.preamble.hash != info?.$2) {
throw ArgumentError('''
Messages file for locale $locale has different hash "${messageList.preamble.hash}" than generated code "${info?.$2}".''');
Expand All @@ -46,11 +42,31 @@ class AboutPageMessages {
}

void loadAllLocales() {
for (var locale in knownLocales) {
for (final locale in knownLocales) {
loadLocale(locale);
}
}

Message pluralSelector(
num howMany, {
required Message other,
Message? few,
Message? many,
Map<int, Message>? numberCases,
Map<int, Message>? wordCases,
}) {
Message getCase(int i) => numberCases?[i] ?? wordCases?[i] ?? other;
return switch (
Intl(locale: Locale.parse(currentLocale)).plural().select(howMany)) {
PluralCategory.zero => getCase(0),
PluralCategory.one => getCase(1),
PluralCategory.two => getCase(2),
PluralCategory.few => few ?? other,
PluralCategory.many => many ?? other,
PluralCategory.other => other,
};
}

String aboutMessage(String websitename) =>
_currentMessages.generateStringAtIndex(0, [websitename]);

Expand Down
2 changes: 1 addition & 1 deletion pkgs/messages/example_json/lib/testarbctx2.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[0,"en","QrwRSsOy",0,null,["About ",[6,0]],["Welcome von <",[8,0],[13,1]],[6,"test ",[3,0,["test new messages",[5,0]],[2,"No new messages",4,"One new message",5,"Two new Messages"]]],[6,"test ",[4,0,"Two new Messages",{"male":"No new messages","female":"One new message"}]],"other"]
[0,"en","QrwRSsOy",0,null,["About ",[6,0]],["Welcome von <",[8,0],[13,1]],[6,"test ",[3,0,["test new messages",[5,0]],[0,"No new messages",1,"One new message","w2","Two new Messages"]]],[6,"test ",[4,0,"Two new Messages",{"male":"No new messages","female":"One new message"}]],"other"]
2 changes: 1 addition & 1 deletion pkgs/messages/example_json/lib/testarbctx2_fr.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[0,"fr","EyPjEJJU",0,null,["Sur ",[4,0]],["Welcome von <",[8,0],[13,1]],[6,"test ",[3,0,["test new messages",[5,0]],[2,"No new messages",4,"One new message",5,"Two new Messages"]]],[6,"test ",[4,0,"Two new Messages",{"male":"No new messages","female":"One new message"}]],"other"]
[0,"fr","EyPjEJJU",0,null,["Sur ",[4,0]],["Welcome von <",[8,0],[13,1]],[6,"test ",[3,0,["test new messages",[5,0]],[0,"No new messages",1,"One new message","w2","Two new Messages"]]],[6,"test ",[4,0,"Two new Messages",{"male":"No new messages","female":"One new message"}]],"other"]
10 changes: 5 additions & 5 deletions pkgs/messages/example_json/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@ environment:
sdk: ^3.0.0

dependencies:
messages:
path: ../
intl4x: ^0.7.0
messages: ^0.2.0

dev_dependencies:
build_daemon: ^4.0.0
build_runner: ^2.3.3
build_web_compilers: ^4.0.5
build_web_compilers: ^3.2.7
dart_flutter_team_lints: ^1.0.0
lints: ^2.0.0
messages_builder:
path: ../../messages_builder
messages_builder: ^0.2.0
path: ^1.8.3
test: ^1.16.0

Expand All @@ -25,3 +24,4 @@ package_options:
generateMethods: true
generateFindById: false
generateFindBy: integer
pluralSelector: intl4x
4 changes: 4 additions & 0 deletions pkgs/messages/example_json/pubspec_overrides.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ dependency_overrides:
path: ../
messages_serializer:
path: ../../messages_serializer
messages_builder:
path: ../../messages_builder
intl4x:
path: ../../intl4x
2 changes: 0 additions & 2 deletions pkgs/messages/lib/messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@
// BSD-style license that can be found in the LICENSE file.

export 'src/deserializer/deserializer.dart';
export 'src/intl_object.dart' show IntlObject;
export 'src/intl_style_lookup.dart' show Intl;
export 'src/message_format.dart';
4 changes: 2 additions & 2 deletions pkgs/messages/lib/src/deserializer/deserializer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import '../intl_object.dart';
import '../message_format.dart';
import '../plural_selector.dart';

abstract class Deserializer<T extends MessageList> {
T deserialize(IntlObject intl);
T deserialize(PluralSelector selector);
}
Loading

0 comments on commit f36d1cf

Please sign in to comment.