l10n 1.2.2

l10n / (gettext-oriented) PO-File Generator #

Translate With GetText PO and POT Files

Important #

Since v1.x xgettext creates locale/templates/LC_MESSAGES/messages.gettext.pot for testing purposes only!!!

mkl10n does'nt use xgettext anymore - instead the l10n.parser-package creates it's own .pot-File!

Before your start: #

Windows #

Sorry guys - this is App is tested under Mac-OSX but should work on Linux without problems.

Supported syntax (.dart + .html) #


    // Translator: Comment I
    _("String to translate");
    l10n("String to translate");

    // Translator: Comment II
    _("String to translate", "Plural form of String");
    l10n("String to translate", "Plural form of String");
    // Translator: Comment III
    print("Hallo ${_('world')}!");
    // Translator: Comment IV
    print("Hallo ${translate(_('world'))}!");
    template = """
        <span translate='yes'>
            <!-- Translator: Comment V -->
            _("String to translate", "Plural form of String");
            l10n("String to translate", "Plural form of String");

The last option has to be used for HTML-"String-Blocks" (""" | ''')

Install #

$ pub global activate l10n

System requirements #

Install the following cmdline-Applications:

  • xgettext (Depreciated since 1.x!)
  • msginit
  • msgmerge

To verify it they are on your system type:

    mkl10n -s 

If you get an error message - do the following:

    $ brew install gettext
    # on Linux: apt-get install gettext

How to use it #

(You have to watch it in 1080p - sorry! Better screencast will follow)

  • Download the example from samples/cmdline
  • Run pub update
  • Run mkl10n .
    Generates the required .po,.pot files and the lib/locale/messages.dart
  • Translate the generated .po-File (locale/<your localr>/messages.po)
  • Run mkl10n . again

Run dart bin/cmdline.dart -s - you should see the translated strings

Play with dart bin/cmdline.dart -l de -s and dart bin/cmdline.dart -l en -s

This is the most important code-part:

    Map<String,String> get settings {
        final Map<String,String> settings = new Map<String,String>();

        // Everything within l10n(...) will be in your .po File
        settings[translate(l10n("loglevel"))]              = loglevel;

        // 'translate' will translate your ID/String 
        settings[translate(l10n("Config folder"))]         = configfolder;
        settings[translate(l10n("Config file"))]           = configfile;
        settings[translate(l10n("Locale"))]                = locale;

        if(dirstoscan.length > 0) {
            settings[translate(l10n("Dirs to scan"))]      = dirstoscan.join(", ");

        return settings;

How to use it with Material Design 4 Dart #

Check out this sample on GitHub:

This sample also shows the usage with Dice - the dependency injection framework

HTML-Translation: (index.html)

    <!-- /* Comment added from HTML-File */ -->
    <span translate>_('Translate me')</span>

Sub-Translations #

Since 0.11.0 Sub-Translations are possible - here is the explanation:

    msgid: "Servermessage {{statuscode-400}}."
    msgstr: "Fehlerhafte Anfrage"
    msgid: "Servermessage {{statuscode-400}}."
    msgstr: ""
    final int major = 400;
    // This produces a msgid "Servermessage {{status}}." in your PO-File.
    // You can translate it as usual 
    final L10N l = new L10N( "Servermessage {{status}}.", { "status"  : "{{statuscode-${major}}}" });
    expect(l.message,"Servermessage {{statuscode-400}}.");

    // No translation for en - so fallback to msgid
    expect(translate(l),"Servermessage {{statuscode-400}}.");

    // But what we really want is what I call Sub-Translation
    translate.locale = "de";
    expect(translate(l),"Fehlerhafte Anfrage");
    Internal way of sub-translation: 
      Replace vars in L10N message -> Servermessage {{statuscode-400}}.
      Check if there is a translation - return it, if not, return the msgid

You have to add the msgid "Servermessage {{statuscode-400}}." by hand to your POT-File.
The rest is done be the nice merging-feature of l10n/msgmerge

If you have problems #

License #

Copyright 2017 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.

If this plugin is helpful for you - please (Circle) me.

Change Log for l10n #

Creates translatable PO-Files, strong orientation to xgettext

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: ^1.2.2

2. Install it

You can install packages from the command line:

with pub:

$ pub get

Alternatively, your editor might support 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.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Analysis issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://dart.dev/dart-2#migration.

Maintenance issues and suggestions

Make sure dartdoc successfully runs on your package's source files. (-10 points)

Dependencies were not resolved.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.12.0 <2.0.0