l10n 1.3.2

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 79

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
    */

<b>Drawback</b><br> You have to add the msgid "Servermessage {{statuscode-400}}." by hand to your <strong>POT</strong>-File.<br> 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.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.3.2"

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages 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';
  
Version Uploaded Documentation Archive
1.3.2 Jun 7, 2018 Go to the documentation of l10n 1.3.2 Download l10n 1.3.2 archive
1.2.11 Mar 26, 2018 Go to the documentation of l10n 1.2.11 Download l10n 1.2.11 archive
1.2.9 Dec 13, 2017 Go to the documentation of l10n 1.2.9 Download l10n 1.2.9 archive
1.2.7 Dec 7, 2017 Go to the documentation of l10n 1.2.7 Download l10n 1.2.7 archive
1.2.2 Dec 6, 2017 Go to the documentation of l10n 1.2.2 Download l10n 1.2.2 archive
1.1.1 Oct 20, 2017 Go to the documentation of l10n 1.1.1 Download l10n 1.1.1 archive
1.1.0 Sep 1, 2017 Go to the documentation of l10n 1.1.0 Download l10n 1.1.0 archive
1.0.1 Aug 25, 2017 Go to the documentation of l10n 1.0.1 Download l10n 1.0.1 archive
1.0.0 Aug 25, 2017 Go to the documentation of l10n 1.0.0 Download l10n 1.0.0 archive
0.19.2 Aug 23, 2017 Go to the documentation of l10n 0.19.2 Download l10n 0.19.2 archive

All 54 versions...

Analysis

We analyzed this package on Jun 19, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.63.0
  • pana: 0.11.3

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
59 / 100
Health:
Code health derived from static analysis. [more]
99 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
79
Learn more about scoring.

Platforms

Detected platforms: Flutter, web, other

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

Suggestions

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 11 hints.

    Run dartfmt to format lib/interfaces.dart.

    Run dartfmt to format lib/l10n.dart.

    Similar analysis of the following files failed:

    • lib/l10n/L10NImpl.dart (hint)
    • lib/l10n/L10NTranslate.dart (hint)
    • lib/locale/messages.dart (hint)
    • lib/parser/Lexer.dart (hint)
    • lib/parser/Parser.dart (hint)
    • lib/parser/Statement.dart (hint)
    • lib/parser/Token.dart (hint)
    • lib/parser/pot.dart (hint)
    • lib/parser/tools.dart (hint)
  • Maintain an example.

    Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use l10n.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.12.0 <2.0.0
args ^1.4.0 1.4.3
console_log_handler >=0.5.0 <1.0.0 0.5.7 1.0.3
dryice ^1.8.0 1.8.3 2.0.15
intl ^0.15.0 0.15.6
logging >=0.11.3 <1.0.0 0.11.3+1
optional ^2.0.0 2.0.1+2
validate ^1.0.0 1.6.0
which ^0.1.3 0.1.3
yaml ^2.1.0 2.1.14
Transitive dependencies
ansicolor 0.0.9 0.1.0
browser 0.10.0+3
charcode 1.1.1
collection 1.14.10
logging_handlers 0.8.0
path 1.6.1
source_span 1.4.0
string_scanner 1.0.2
supports_color 0.1.1
when 0.2.0
Dev dependencies
build_runner ^0.8.0
build_test ^0.10.0
build_web_compilers ^0.4.0
test any