Permalink
Browse files

doc: Better documentation

  • Loading branch information...
MikeMitterer committed Aug 22, 2017
1 parent 0585620 commit 61426f3f2b169c85393b71471012744c0c155200
View
@@ -2,6 +2,9 @@ l10n / (gettext-oriented) PO-File Generator
-------------------------------------------
> Helps to localize your application
Before your start:
- [A Quick Gettext Tutorial](http://www.labri.fr/perso/fleury/posts/programming/a-quick-gettext-tutorial.html)
#### Install
```bash
$ pub global activate l10n
@@ -215,6 +218,9 @@ The rest is done be the nice merging-feature of l10n/msgmerge
* 0.11.0 - Sub-Translations are possible, msginit gets initialized with utf-8 per default
* 0.9.0 - Released on pub
## Links
- [GNU gettext utilities](https://www.gnu.org/software/gettext/manual/gettext.html)
### License
Copyright 2016 Michael Mitterer (office@mikemitterer.at),
View
@@ -103,8 +103,8 @@ class Application {
buffer.writeln("library $libPrefix.locale;\n");
buffer.writeln('/**');
buffer.writeln('* DO NOT EDIT. This is code generated via pkg/l10n/bin/mkl10llocale.dart');
buffer.writeln('* This is a library that provides messages for all your locales.');
buffer.writeln('* DO NOT EDIT. This is code generated with:');
buffer.writeln('* projectdir \$ mkl10llocale .');
buffer.writeln('*/');
buffer.writeln("");
buffer.writeln("import 'package:l10n/l10n.dart';");
@@ -169,7 +169,8 @@ class Application {
_logger.fine(" -> ${file.path}");
// --from-code ... iconv -l shows all the available codes!
final ProcessResult result = xgettext.runSync(['-kl10n', '-kL10N', '-j', '-o', "$potfile", '-L', 'JavaScript','--from-code=utf-8', file.path ]);
String language = 'JavaScript';
final ProcessResult result = xgettext.runSync(['-kl10n', '-kL10N', '-k_', '-c' , '-j', '-o', "$potfile", '-L', language ,'--from-code=utf-8', '-s', file.path ]);
if (result.exitCode != 0) {
_logger.severe("${result.stderr}");
@@ -205,6 +206,11 @@ class Application {
return entity.path.contains(regexp);
}
if(entity.path.startsWith(".pub/") || entity.path.startsWith("./.pub/") ||
entity.path.startsWith("build/") || entity.path.startsWith("./build/")){
return false;
}
return true;
}).map((final FileSystemEntity entity) => new File(entity.path))
@@ -222,6 +228,10 @@ class Application {
});
print("");
print(translate(l10n("Example:")));
print(" " + translate(l10n("mkl10nlocale . - Generates lib/locale/messages.dart")));
print(" " + translate(l10n("mkl10nlocale -l en,de . - Generates translation for en + de")));
print("");
}
void _printSettings(final Map<String,String> settings) {
@@ -245,8 +255,10 @@ class Application {
});
print("");
// You will see this comment in the .po/.pot-File
print(translate(l10n("External commands:")));
[ msgmerge, msginit, xgettext].forEach((final ShellCommand command) {
[ xgettext, msginit, msgmerge ].forEach((final ShellCommand command) {
String exe = translate(l10n("not installed!"));
try {
exe = command.executable;
@@ -277,7 +289,10 @@ class Application {
final Completer<Map<String,String>> completer = new Completer<Map<String,String>>();
final Map<String,Map<String,String>> json = new HashMap<String,Map<String,String>>();
json[locale] = new HashMap<String,String>();
json[locale] = new SplayTreeMap<String,String>((final String key1,final String key2) {
// sort case insensitive
return key1.toLowerCase().compareTo(key2.toLowerCase());
});
if(pofile.existsSync()) {
final File jsonFile = new File(pofile.path.replaceFirst(new RegExp("\.po"),".json"));
@@ -296,16 +311,20 @@ class Application {
}
// If there is a header - skip it!
final bool skipHeader = content.contains("Project-Id-Version");
msgblocks.skip(skipHeader ? 1 : 0).forEach((final String block) {
msgblocks.skip(skipHeader ? 1 : 0).where((final String block) => block.trim().isNotEmpty)
.forEach((final String block) {
final String withoutcomment = block.replaceAll(new RegExp("#.*(\r\n|\n)"),"");
final List<String> message = withoutcomment.split("msgstr");
final String key = _sanitize(message[0].replaceFirst("msgid",""));
final String value = _sanitize(message[1]);
if(withoutcomment.isNotEmpty) {
final String key = _sanitize(message[0].replaceFirst("msgid", ""));
final String value = _sanitize(message[1]);
json[locale][key] = value;
json[locale][key] = value;
}
});
jsonFile.writeAsString(_makePrettyJsonString(json)).then((final File file) {
_logger.fine("${file.path} created!");
completer.complete(json[locale]);
View
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Simple HTML</title>
</head>
<body>
<div>
<!-- /* Hallo Kommentar aus HTML */ -->
<span translate>_('Angular way8')</span>
</div>
</body>
</html>
View
@@ -1,8 +1,8 @@
library l10n.locale;
/**
* DO NOT EDIT. This is code generated via pkg/l10n/bin/mkl10llocale.dart
* This is a library that provides messages for all your locales.
* DO NOT EDIT. This is code generated with:
* projectdir $ mkl10llocale .
*/
import 'package:l10n/l10n.dart';
@@ -11,36 +11,35 @@ import 'package:l10n/l10n.dart';
final L10NTranslate translate = new L10NTranslate.withTranslations( {
"de": {
"\"\n\"Hallo,\\n\"\n\" dies ist ein {{what}}": "",
"Defines where to place your locale-Dir": "Definiert Basisverzeichnis für das locale-Directory",
"Settings:": "",
"Mike + {{name}}": "",
"\"\n\"Hallo\\n\"\n\"Test": "",
"This is a test": "",
"Angular way7": "",
"Angular way8": "",
"Defines where to place your locale-Dir": "Definiert das locale-Verzeichnis",
"Dirs to scan": "",
"Example:": "Beispiele:",
"External commands:": "Externe Befehle:",
"Hallo Mike": "",
"Hallo Mike II": "",
"Hallo {{?}}": "",
"Usage: mkl10nlocale [options] <dir(s) to scan>": "Verwendung: mkl10nlocale [options] <dir(s) to scan>",
"Hallo {{l10n}}": "",
"locales - separated by colon, Sample: --locales en,de,es": "locales - getrennt durch Beistrich, Sample: --locales en,de,es",
"Der Server meldet {{statuscode-401}} bei der API-Key Anforderung.": "",
"Hallo {{name}}": "",
"Hallo {{name}}, du bist jetzt {{age}} Jahre alt": "",
"Hallo Mike": "",
"Libprefix for generated DART-File (library <prefix>.locale;)": "Library-Prefix für das generierte DART-File (library <prefix>.locale;)",
"not installed!": "",
"Der Server meldet {{statuscode-400}} bei der API-Key Anforderung.": "Fehlerhafte Anfrage (400) bei der API-Key Anforderung!",
"External commands:": "Externe programme:",
"Test1": "",
"Hallo, dies ist ein {{what}}": "",
"Dirs to scan": "Directory dass durchsucht werden soll",
"Shows this message": "Zeigt diese Message an",
"Hello {{what}}": "",
"RTL": "",
"Hallo, {{name}}": "",
"LTR": "",
"Where should the DART-File go? (<path>/locale/messages.dart)": "Wo soll das DART-File generiert werden? (<pfad>/locale/messages.dart)",
"Ein TEST - 290714 1648": "",
"Prints settings": "Zeigt die aktuellen settings an",
"UNKNOWN": "",
"Hallo {{name}}": ""
"Hello {{what}}": "",
"Libprefix for generated DART-File (library <prefix>.locale;)": "Prefix für die generiert Library (library <prefix>.locale;)",
"locales - separated by colon, Sample: --locales en,de,es": "locales - getrennt durch Beistrich, Beispiel: --locales en,de,es",
"Mike + {{name}}": "",
"mkl10nlocale -l en,de . - Generates translation for en + de": "mkl10nlocale -l en,de . - Erstellt die Übersetzungen für en + de",
"mkl10nlocale . - Generates lib/locale/messages.dart": "mkl10nlocale . - Erstellt lib/locale/messages.dart",
"not installed!": "",
"Prints settings": "Zeigt die Settings an",
"Settings:": "Einstellungen:",
"Shows this message": "",
"Test1": "",
"This is a test": "",
"Usage: mkl10nlocale [options] <dir(s) to scan>": "Verwendung: mkl10nlocale [optionen] <Scan-Verzeichnis>",
"Where should the DART-File go? (<path>/locale/messages.dart)": "Wo soll das generierte Dart-File (messages.dart) erstellt werden"
}
});
@@ -1,35 +1,34 @@
{
"de": {
"\"\n\"Hallo,\\n\"\n\" dies ist ein {{what}}": "",
"Defines where to place your locale-Dir": "Definiert Basisverzeichnis für das locale-Directory",
"Settings:": "",
"Mike + {{name}}": "",
"\"\n\"Hallo\\n\"\n\"Test": "",
"This is a test": "",
"Angular way7": "",
"Angular way8": "",
"Defines where to place your locale-Dir": "Definiert das locale-Verzeichnis",
"Dirs to scan": "",
"Example:": "Beispiele:",
"External commands:": "Externe Befehle:",
"Hallo Mike": "",
"Hallo Mike II": "",
"Hallo {{?}}": "",
"Usage: mkl10nlocale [options] <dir(s) to scan>": "Verwendung: mkl10nlocale [options] <dir(s) to scan>",
"Hallo {{l10n}}": "",
"locales - separated by colon, Sample: --locales en,de,es": "locales - getrennt durch Beistrich, Sample: --locales en,de,es",
"Der Server meldet {{statuscode-401}} bei der API-Key Anforderung.": "",
"Hallo {{name}}": "",
"Hallo {{name}}, du bist jetzt {{age}} Jahre alt": "",
"Hallo Mike": "",
"Libprefix for generated DART-File (library <prefix>.locale;)": "Library-Prefix für das generierte DART-File (library <prefix>.locale;)",
"not installed!": "",
"Der Server meldet {{statuscode-400}} bei der API-Key Anforderung.": "Fehlerhafte Anfrage (400) bei der API-Key Anforderung!",
"External commands:": "Externe programme:",
"Test1": "",
"Hallo, dies ist ein {{what}}": "",
"Dirs to scan": "Directory dass durchsucht werden soll",
"Shows this message": "Zeigt diese Message an",
"Hello {{what}}": "",
"RTL": "",
"Hallo, {{name}}": "",
"LTR": "",
"Where should the DART-File go? (<path>/locale/messages.dart)": "Wo soll das DART-File generiert werden? (<pfad>/locale/messages.dart)",
"Ein TEST - 290714 1648": "",
"Prints settings": "Zeigt die aktuellen settings an",
"UNKNOWN": "",
"Hallo {{name}}": ""
"Hello {{what}}": "",
"Libprefix for generated DART-File (library <prefix>.locale;)": "Prefix für die generiert Library (library <prefix>.locale;)",
"locales - separated by colon, Sample: --locales en,de,es": "locales - getrennt durch Beistrich, Beispiel: --locales en,de,es",
"Mike + {{name}}": "",
"mkl10nlocale -l en,de . - Generates translation for en + de": "mkl10nlocale -l en,de . - Erstellt die Übersetzungen für en + de",
"mkl10nlocale . - Generates lib/locale/messages.dart": "mkl10nlocale . - Erstellt lib/locale/messages.dart",
"not installed!": "",
"Prints settings": "Zeigt die Settings an",
"Settings:": "Einstellungen:",
"Shows this message": "",
"Test1": "",
"This is a test": "",
"Usage: mkl10nlocale [options] <dir(s) to scan>": "Verwendung: mkl10nlocale [optionen] <Scan-Verzeichnis>",
"Where should the DART-File go? (<path>/locale/messages.dart)": "Wo soll das generierte Dart-File (messages.dart) erstellt werden"
}
}
Oops, something went wrong.

0 comments on commit 61426f3

Please sign in to comment.