l10n 2.0.19

  • Readme
  • Changelog
  • Installing
  • 62

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(message());
    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...

Sure!

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

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

   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.


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 #

  • Usage in README cb711d1
  • Cleanup + prepearing a new test-sample 7add301

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 #

  • New sample-video, better README 79f985d
  • cmdline-Sample added 406e9a5

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 #

  • Grinder + new test-format f0fbeff

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

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

  • Dart: 2.6.1
  • pana: 0.13.1+4

Health issues and suggestions

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

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

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

line 30 col 28: Unnecessary new keyword.

line 72 col 25: Unnecessary new keyword.

line 83 col 20: 'parseCompilationUnit' is deprecated and shouldn't be used. Please use parseString instead.

line 92 col 24: Unnecessary new keyword.

Fix lib/parser/Lexer.dart. (-14.82 points)

Analysis of lib/parser/Lexer.dart reported 32 hints, including:

line 46 col 33: Unnecessary new keyword.

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

line 81 col 37: Unnecessary new keyword.

line 85 col 37: Unnecessary new keyword.

line 117 col 37: Unnecessary new keyword.

Fix lib/pot.dart. (-8.17 points)

Analysis of lib/pot.dart reported 17 hints, including:

line 51 col 45: Unnecessary new keyword.

line 52 col 44: Unnecessary new keyword.

line 75 col 35: Unnecessary new keyword.

line 81 col 53: Unnecessary new keyword.

line 93 col 24: Unnecessary new keyword.

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

Additional issues in the following files:

  • lib/parser/Parser.dart (12 hints)
  • lib/l10n/L10NImpl.dart (11 hints)
  • bin/argparser/Config.dart (7 hints)
  • lib/codegen.dart (5 hints)
  • lib/_l10n/messages_all.dart (4 hints)
  • lib/arb.dart (4 hints)
  • lib/extractor/HTMLExtraction.dart (4 hints)
  • lib/utils.dart (4 hints)
  • bin/mkl10n.dart (3 hints)
  • lib/l10n.dart (3 hints)
  • lib/parser/Token.dart (3 hints)
  • lib/parser/tools.dart (3 hints)
  • lib/arb/ARB.dart (2 hints)
  • bin/argparser/Options.dart (1 hint)
  • lib/_l10n/messages_de.dart (1 hint)
  • lib/extractor.dart (1 hint)
  • lib/extractor/L10NMessageExtractionException.dart (1 hint)
  • lib/parser.dart (1 hint)
  • lib/parser/Statement.dart (1 hint)
  • 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.)

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.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
analyzer >=0.32.0 <1.0.0 0.38.5 0.39.2+1
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.5.0
yaml ^2.1.0 2.2.0
Transitive dependencies
ansicolor 1.0.2
async 2.4.0
build_cli_annotations 1.1.0
charcode 1.1.2
collection 1.14.12
convert 2.1.1
crypto 2.1.4
csslib 0.16.1
dart_style 1.3.3
front_end 0.1.27 0.1.29
glob 1.2.0
html 0.14.0+3
js 0.6.1+1
kernel 0.3.27 0.3.29
meta 1.1.8
node_interop 1.0.3
node_io 1.0.1+2
package_config 1.1.0
pedantic 1.9.0
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+13
Dev dependencies
build_runner any
build_test any
build_web_compilers any
test any