Skip to content

Commit

Permalink
doc: Browser-Sample got a separate _initLanguageSettings-function
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeMitterer committed Sep 15, 2018
1 parent a05d0f2 commit cb0734c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion samples/browser/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
34 changes: 21 additions & 13 deletions samples/browser/web/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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.