Permalink
Browse files

doc: Browser-Sample got a separate _initLanguageSettings-function

  • Loading branch information...
MikeMitterer committed Sep 15, 2018
1 parent a05d0f2 commit cb0734c4e3b51fc43bf5beb816177155ec02e320
Showing with 22 additions and 14 deletions.
  1. +1 −1 samples/browser/web/index.html
  2. +21 −13 samples/browser/web/main.dart
@@ -40,7 +40,7 @@
<footer id="pageFooter" class="dark-mode">
<div>Sample for pub-package:
<a href="https://pub.dartlang.org/packages/l10n" target="_blank">l10n</a>
<span class="published">/ published: <span class="pubdate">2018-09-15 / 09:10:07</span></span>
<span class="published">/ published: <span class="pubdate">2018-09-15 / 10:17:40</span></span>
</div>
<div>
@@ -9,6 +9,25 @@ import 'package:l10n/l10n.dart';
import 'package:browser_example/_l10n/messages_all.dart';
Future main() async {
final String locale = await _initLanguageSettings();
(dom.querySelector("head") as dom.HeadElement).lang = locale;
dom.querySelectorAll('.translate')
.map((final dom.Element element) => element as dom.HtmlElement)
.forEach((final dom.HtmlElement element) {
element.text = element.text.replaceAllMapped(RegExp(r'_\("(.*)"\)', multiLine: true),
(final Match match) {
return l10n(match.group(1));
});
});
dom.querySelector("body").classes.remove("loading");
}
/// Initialize the Intl-Framework
///
Future<String> _initLanguageSettings() async {
// Determine your locale
final String locale = await findSystemLocale();
final String shortLocale = Intl.shortLocale(Uri.base.queryParameters['lang'] ?? locale);
@@ -24,16 +43,5 @@ Future main() async {
// Initialize translation-table
await initializeMessages(shortLocale);
(dom.querySelector("head") as dom.HeadElement).lang = shortLocale;
dom.querySelectorAll('.translate')
.map((final dom.Element element) => element as dom.HtmlElement)
.forEach((final dom.HtmlElement element) {
element.text = element.text.replaceAllMapped(RegExp(r'_\("(.*)"\)', multiLine: true),
(final Match match) {
return l10n(match.group(1));
});
});
dom.querySelector("body").classes.remove("loading");
}
return shortLocale;
}

0 comments on commit cb0734c

Please sign in to comment.