l10n 1.4.0

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) #

.dart-File:

    // 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");
        </span>
    """

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 #

Screenshot)
(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:
cmdline/Config.dart

    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:

locale/de/.../messages.po: 
    msgid: "Servermessage {{statuscode-400}}."
    msgstr: "Fehlerhafte Anfrage"
    
locale/en/.../messages.po: 
    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
    */

Drawback
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

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, 
software distributed under the License is distributed on an 
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
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.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:


dependencies:
  l10n: ^1.4.0

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';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
74
Health:
Code health derived from static analysis. [more]
87
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
79
Learn more about scoring.

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

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms: Flutter, web, other

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

Health suggestions

Fix bin/mkl10n.dart. (-2.48 points)

Analysis of bin/mkl10n.dart reported 5 hints:

line 46 col 51: Use isEmpty instead of length

line 46 col 84: Use isEmpty instead of length

line 76 col 17: Future results in async function bodies must be awaited or marked unawaited using package:pedantic.

line 92 col 115: Use = to separate a named parameter from its default value.

line 245 col 24: Use isNotEmpty instead of length

Fix lib/l10n/L10NTranslate.dart. (-2.48 points)

Analysis of lib/l10n/L10NTranslate.dart reported 5 hints:

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

line 18 col 93: Use = to separate a named parameter from its default value.

line 35 col 83: Use = to separate a named parameter from its default value.

line 109 col 5: Avoid return types on setters.

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

Fix bin/commands/ShellCommand.dart. (-1.99 points)

Analysis of bin/commands/ShellCommand.dart reported 4 hints:

line 43 col 42: Use = to separate a named parameter from its default value.

line 44 col 28: Use = to separate a named parameter from its default value.

line 45 col 36: Use = to separate a named parameter from its default value.

line 46 col 36: Use = to separate a named parameter from its default value.

Fix additional 14 files with analysis or formatting issues. (-6.97 points)

Additional issues in the following files:

  • lib/l10n/L10NImpl.dart (3 hints)
  • 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/parser.dart (1 hint)
  • bin/argparser/Options.dart (Run dartfmt to format bin/argparser/Options.dart.)
  • bin/commands/commands.dart (Run dartfmt to format bin/commands/commands.dart.)
  • lib/interfaces.dart (Run dartfmt to format lib/interfaces.dart.)
  • lib/l10n.dart (Run dartfmt to format lib/l10n.dart.)
  • lib/locale/messages.dart (Run dartfmt to format lib/locale/messages.dart.)
  • lib/parser/Statement.dart (Run dartfmt to format lib/parser/Statement.dart.)
  • lib/parser/pot.dart (Run dartfmt to format lib/parser/pot.dart.)
  • lib/parser/tools.dart (Run dartfmt to format lib/parser/tools.dart.)

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (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.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
args ^1.4.0 1.5.2
console_log_handler >=1.1.0 <2.0.0 1.1.6
dryice ^2.0.0 2.0.26
intl ^0.15.0 0.15.8
logging >=0.11.3 <1.0.0 0.11.3+2
optional ^3.0.0 3.0.2+1
validate ^1.0.0 1.7.0
where ^4.3.0 4.4.0 6.3.0
yaml ^2.1.0 2.1.16
Transitive dependencies
analyzer 0.34.3 0.37.0
ansicolor 1.0.2
async 2.2.0
build 1.1.0 1.1.4
build_cli_annotations 1.1.0
build_config 0.3.2 0.4.1
build_daemon 0.2.3 1.1.0
build_resolvers 0.2.3 1.0.5
build_runner_core 2.0.1 3.0.6
built_collection 4.2.2
built_value 6.7.0
charcode 1.1.2
code_builder 3.2.0
collection 1.14.11
convert 2.1.1
crypto 2.0.6
csslib 0.16.1
dart_style 1.2.3 1.2.9
fixnum 0.10.9
front_end 0.1.9+1 0.1.20
glob 1.1.7
graphs 0.2.0
html 0.14.0+2
http 0.12.0+2
http_multi_server 2.1.0
http_parser 3.1.3
io 0.3.3
js 0.6.1+1
json_annotation 2.4.0
kernel 0.3.9+1 0.3.20
matcher 0.12.5
meta 1.1.7
mime 0.9.6+3
package_config 1.0.5
package_resolver 1.0.10
path 1.6.2
pedantic 1.8.0+1
plugin 0.2.0+3
pool 1.4.0
pub_semver 1.4.2
pubspec_parse 0.1.4
quiver 2.0.3
reflectable 2.0.12
shelf 0.7.5
shelf_web_socket 0.2.3
source_span 1.5.5
stack_trace 1.9.3
stream_channel 2.0.0
stream_transform 0.0.19
string_scanner 1.0.4
term_glyph 1.1.0
timing 0.1.1+1
typed_data 1.1.6
watcher 0.9.7+10
web_socket_channel 1.0.14
Dev dependencies
build_runner any 1.2.3 1.6.1
build_test any
build_web_compilers any
test any

Admin