-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
554 additions
and
468 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
|
||
# Conventional directory for build output. | ||
build/ | ||
bin/example/ |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file | ||
// 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 'package:messages_builder/hook.dart'; | ||
import 'package:native_assets_cli/native_assets_cli.dart'; | ||
|
||
void main(List<String> args) { | ||
build(args, (config, output) async { | ||
// final builder = MessagesDataBuilder.fromFiles( | ||
// [ | ||
// 'assets/l10n/testarb.arb', | ||
// 'assets/l10n/testarb_de.arb', | ||
// 'assets/l10n/testarbctx2.arb', | ||
// 'assets/l10n/testarbctx2_fr.arb', | ||
// ], | ||
// ); | ||
final builder = MessagesDataBuilder.fromFolder('assets/l10n/'); | ||
|
||
await builder.run(config: config, output: output, logger: null); | ||
}); | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
// Generated by package:messages_builder. | ||
|
||
import 'dart:ffi'; | ||
|
||
import 'package:intl4x/intl4x.dart'; | ||
import 'package:messages/messages_json.dart'; | ||
|
||
class AboutPageMessages { | ||
AboutPageMessages(); | ||
|
||
String _currentLocale = 'en'; | ||
|
||
final Map<String, MessageList> _messages = {}; | ||
|
||
static const _dataFiles = { | ||
'fr': ('package:example_json/assets/l10n/testarbctx2_fr.json', 'EyPjEJJU'), | ||
'en': ('package:example_json/assets/l10n/testarbctx2.json', 'QrwRSsOy') | ||
}; | ||
|
||
String get currentLocale => _currentLocale; | ||
|
||
MessageList get _currentMessages => _messages[currentLocale]!; | ||
|
||
static Iterable<String> get knownLocales => _dataFiles.keys; | ||
|
||
Future<void> loadLocale(String locale) async { | ||
if (!_messages.containsKey(locale)) { | ||
final info = _dataFiles[locale]; | ||
final carb = info?.$1; | ||
if (carb == null) { | ||
throw ArgumentError('Locale $locale is not in $knownLocales'); | ||
} | ||
final data = await AssetBundle.loadString(carb); | ||
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}".'''); | ||
} | ||
_messages[locale] = messageList; | ||
} | ||
_currentLocale = locale; | ||
} | ||
|
||
void loadAllLocales() { | ||
for (final locale in knownLocales) { | ||
loadLocale(locale); | ||
} | ||
} | ||
|
||
String aboutMessage(String websitename) => | ||
_currentMessages.generateStringAtIndex(0, [websitename]); | ||
|
||
String helloAndWelcome( | ||
String firstName, | ||
int lastName, | ||
) => | ||
_currentMessages.generateStringAtIndex(1, [firstName, lastName]); | ||
|
||
String newMessages(int newMessages) => | ||
_currentMessages.generateStringAtIndex(2, [newMessages]); | ||
|
||
String newMessages2( | ||
String gender, | ||
int newVar, | ||
) => | ||
_currentMessages.generateStringAtIndex(3, [gender, newVar]); | ||
|
||
String get otherMsg => _currentMessages.generateStringAtIndex(4, []); | ||
} | ||
|
||
class HomePageMessages { | ||
HomePageMessages(); | ||
|
||
String _currentLocale = 'en'; | ||
|
||
final Map<String, MessageList> _messages = {}; | ||
|
||
static const _dataFiles = { | ||
'de': ('package:example_json/assets/l10n/testarb_de.json', 'hbDN1MhX'), | ||
'en': ('package:example_json/assets/l10n/testarb.json', 'dr9Md951') | ||
}; | ||
|
||
String get currentLocale => _currentLocale; | ||
|
||
MessageList get _currentMessages => _messages[currentLocale]!; | ||
|
||
static Iterable<String> get knownLocales => _dataFiles.keys; | ||
|
||
Future<void> loadLocale(String locale) async { | ||
if (!_messages.containsKey(locale)) { | ||
final info = _dataFiles[locale]; | ||
final carb = info?.$1; | ||
if (carb == null) { | ||
throw ArgumentError('Locale $locale is not in $knownLocales'); | ||
} | ||
final data = await AssetBundle.loadString(carb); | ||
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}".'''); | ||
} | ||
_messages[locale] = messageList; | ||
} | ||
_currentLocale = locale; | ||
} | ||
|
||
void loadAllLocales() { | ||
for (final locale in knownLocales) { | ||
loadLocale(locale); | ||
} | ||
} | ||
|
||
String helloAndWelcome( | ||
String firstName, | ||
String lastName, | ||
) => | ||
_currentMessages.generateStringAtIndex(0, [firstName, lastName]); | ||
|
||
String helloAndWelcome2( | ||
String firstName, | ||
String lastName, | ||
) => | ||
_currentMessages.generateStringAtIndex(1, [firstName, lastName]); | ||
|
||
String newMessages(int newMessages) => | ||
_currentMessages.generateStringAtIndex(2, [newMessages]); | ||
|
||
String newMessages2( | ||
String gender, | ||
int newVar, | ||
) => | ||
_currentMessages.generateStringAtIndex(3, [gender, newVar]); | ||
} | ||
|
||
Message _pluralSelector( | ||
num howMany, | ||
String locale, { | ||
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(locale)).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, | ||
}; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.