l10n 2.0.19

l10n #

Easy to use generator for .arb-Files
Helps if you want to translate your application

l10n >= v2.x #

This is a complete rewrite. l10n now fully supports Intl.message and .ARB-Files

Usage #

  • First install l10n with pub global activate l10n

Now mkl10n should be available on the command-line.

Go to the package you want to translate.

    mkl10n -l de .

Yes - that's it!

Your .arb-Files are in l10n. You should see intl_messages.arb and intl_de.arb

Translate intl_de.arb

    # Run this command again
    mkl10n -l de .

Your generated dart-Files are in lib/_l10. You should see messages_all.dart and messages_de.dart

Import messages_all.dart in your app.

// Include this if you run your app in the browser
import 'package:intl/intl_browser.dart';

// Include this if you run your app on the cmdline
import 'package:intl/intl_standalone.dart';

import 'package:l10n/l10n.dart';
import 'package:<your package>/_l10n/messages_all.dart';

void main() async {
    // Init section
    final shortLocale = await initLanguageSettings(
        () => findSystemLocale(),
        (final String locale) => initializeMessages(locale)
    // Set "lang" in the DOM
    (dom.querySelector("head") as dom.HeadElement).lang = locale;

    // App specific code
    // ...
    String message() => Intl.message("First test");
    print(l10n("Second test"));

    [ "Mike", "Gerda", "Sarh"].forEach((name) {
        print(l10n("Good morning [name]",{ "name" : name }));
    // ...

On GitHub you can find a cmdline-example and a browser-example.

Browser-Example Live-Version This is the most simple version of a translated HTML-page I could think of...

More details #

As mentioned above Intl.message is fully supported. More infos can be found on pub

Hey but there is more! #

In my opinion Intl.message is to complex for most situations so I also support my own l10n syntax.

    // Yup - this prints 'Second test'
    // And after you have translated the intl_de.arb to German it prints 'Zweiter Test' 
    print(l10n("Second test"));

Check out the source on GitHub

But hey - we also have HTML-Files...


<main class="cols">
       <div class="translate">_("Hi Mike")</div>
       <div class="translate">_("My cat's name is 'Pebbles'")</div>

That's how it works in HTML. Wrap the string you want to translate with _(...) You can also wrap it with l10n(...) but I prefer _(...)

It get's even better - if you have a dart-File with HTML-Included like so
it's also fully scanned by mkl10n

Flutter #

This should seamlessly work with Flutter. Should because I haven't tested it with Flutter
If it fails please write file an issue report.

If you have problems #

License #

Copyright 2018 Michael Mitterer (office@mikemitterer.at), 
IT-Consulting and Development Limited, Austrian Branch

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at


Unless required by applicable law or agreed to in writing, 
software distributed under the License is distributed on an 
either express or implied. See the License for the specific language 
governing permissions and limitations under the License.

Change Log for l10n #

Creates translatable PO-Files, strong orientation to xgettext

Unreleased #

Feature #

  • initLanguageSetting shortens the init-section in main 09537d8
  • Easy translation with mkl10n 7c6f264

Bugs #

  • Browser didn't show the right language if Browser-Language was just English a05d0f2
  • Language does not change on client-side 23f6700

Docs #

  • Better documentation for example 1d30157
  • Browser-Sample got a separate _initLanguageSettings-function cb0734c
  • Typos in README 02c4201

Refactor #

  • loosened constraint to analyzer 2cabd6f

v1.4 - 2018-08-29

Refactor #

v1.3 - 2018-06-06

Feature #

Docs #

Refactor #

v1.1.0 - 2017-09-01

Feature #

  • l10 in String interpolation 3a590dc

Docs #

v1.0.1 - 2017-08-25

Docs #

v1.0 - 2017-08-25

Feature #

  • xgettext is Depreciated - mkl10n writes the POT-File 8727b6e

v0.19.2 - 2017-08-23

Docs #

v0.19.1 - 2017-08-23

Docs #

v0.19.0 - 2017-08-23

Feature #

  • Define settings in Settings-File (.mkl10n.yaml), Sort output by file location 1e18a7e

v0.18.0 - 2017-08-22

Docs #

v0.17.0 - 2017-08-17

Feature #

  • External programs are now a subclass of ShellCommand, structure improved 3fc1c82

v0.16.4 - 2016-11-16

Docs #

  • Strong-Mode support, README improved 5532669

v0.16.2 - 2015-12-16

Docs #

  • More documentation for translate + sample 3f0445b

v0.16.1 - 2015-12-04

Docs #

This CHANGELOG.md was generated with Changelog for Dart

Use this package as an executable

1. Install it

You can install the package from the command line:

$ pub global activate l10n

2. Use it

The package has the following executables:

$ mkl10n

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  l10n: ^2.0.19

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:l10n/l10n.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Sep 20, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.0
  • pana: 0.12.21


Detected platforms: Flutter, web, other

No platform restriction found in primary library package:l10n/l10n.dart.

Health issues and suggestions

Fix lib/extractor/L10NMessageExtraction.dart. (-25.75 points)

Analysis of lib/extractor/L10NMessageExtraction.dart failed with 1 error, 2 hints:

line 159 col 56: The name 'MapLiteral' isn't defined, so it can't be used in an 'is' expression.

line 83 col 20: 'parseCompilationUnit' is deprecated and shouldn't be used.

line 150 col 12: Use isEmpty instead of length

Fix lib/l10n.dart. (-1.49 points)

Analysis of lib/l10n.dart reported 3 hints:

line 49 col 1: The class 'Future' wasn't exported from 'dart:core' until version 2.1, but this code is required to be able to run on earlier versions.

line 50 col 5: The class 'Future' wasn't exported from 'dart:core' until version 2.1, but this code is required to be able to run on earlier versions.

line 51 col 5: The class 'Future' wasn't exported from 'dart:core' until version 2.1, but this code is required to be able to run on earlier versions.

Fix lib/l10n/L10NImpl.dart. (-1.49 points)

Analysis of lib/l10n/L10NImpl.dart reported 3 hints:

line 5 col 1: Prefer using /// for doc comments.

line 23 col 35: Don't type annotate initializing formals.

line 105 col 1: Prefer using /// for doc comments.

Fix additional 22 files with analysis or formatting issues. (-6.98 points)

Additional issues in the following files:

  • lib/parser/Lexer.dart (3 hints)
  • lib/parser/Token.dart (3 hints)
  • bin/argparser/Config.dart (2 hints)
  • lib/parser/Parser.dart (2 hints)
  • lib/arb/ARB.dart (1 hint)
  • lib/extractor.dart (1 hint)
  • lib/extractor/L10NMessageExtractionException.dart (1 hint)
  • lib/parser.dart (1 hint)
  • bin/argparser/Options.dart (Run dartfmt to format bin/argparser/Options.dart.)
  • bin/mkl10n.dart (Run dartfmt to format bin/mkl10n.dart.)
  • lib/_l10n/messages_all.dart (Run dartfmt to format lib/_l10n/messages_all.dart.)
  • lib/_l10n/messages_de.dart (Run dartfmt to format lib/_l10n/messages_de.dart.)
  • lib/arb.dart (Run dartfmt to format lib/arb.dart.)
  • lib/codegen.dart (Run dartfmt to format lib/codegen.dart.)
  • lib/extractor/HTMLExtraction.dart (Run dartfmt to format lib/extractor/HTMLExtraction.dart.)
  • lib/interfaces.dart (Run dartfmt to format lib/interfaces.dart.)
  • lib/parser/InvalidTokenException.dart (Run dartfmt to format lib/parser/InvalidTokenException.dart.)
  • lib/parser/ParserError.dart (Run dartfmt to format lib/parser/ParserError.dart.)
  • lib/parser/Statement.dart (Run dartfmt to format lib/parser/Statement.dart.)
  • lib/parser/tools.dart (Run dartfmt to format lib/parser/tools.dart.)
  • lib/pot.dart (Run dartfmt to format lib/pot.dart.)
  • lib/utils.dart (Run dartfmt to format lib/utils.dart.)

Maintenance issues and suggestions

Support latest dependencies. (-20 points)

The version constraint in pubspec.yaml does not support the latest published versions for 2 dependencies (intl, where).

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and l10n.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
analyzer >=0.32.0 <1.0.0 0.38.3
args ^1.4.0 1.5.2
console_log_handler >=1.1.0 <2.0.0 1.1.6
intl ^0.15.0 0.15.8 0.16.0
intl_translation ^0.17.0 0.17.7
logging >=0.11.3 <1.0.0 0.11.3+2
optional ^3.0.0 3.1.0
path ^1.0.0 1.6.4
validate ^1.0.0 1.7.0
where ^4.3.0 4.4.0 6.4.0
yaml ^2.1.0 2.2.0
Transitive dependencies
ansicolor 1.0.2
async 2.3.0
build_cli_annotations 1.1.0
charcode 1.1.2
collection 1.14.12
convert 2.1.1
crypto 2.1.3
csslib 0.16.1
dart_style 1.2.10
front_end 0.1.25
glob 1.1.7
html 0.14.0+2
kernel 0.3.25
meta 1.1.7
package_config 1.1.0
pedantic 1.8.0+1
petitparser 2.4.0
pub_semver 1.4.2
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
watcher 0.9.7+12
Dev dependencies
build_runner any
build_test any
build_web_compilers any
test any