gettext 1.1.0+2

  • Readme
  • Changelog
  • Example
  • Installing
  • 84

Dart Gettext #

A Dart implementation of gettext, a localization framework.

Ported node-gettext package to dart.

Also works perfectly with flutter.

Features #

  • Supports domains, contexts and plurals
  • Ships with plural forms for 136 languages
  • Change locale or domain on the fly
  • Emits events for internal errors, such as missing translations

Usage #

import "package:gettext/gettext.dart";

final gt = new Gettext(onWarning: print);

Load messages from .json file:

new File("./en_US.json").readAsString().then(
   (data) {
       final gt = new Gettext();

Load messages from .mo or .po files using gettext_parser:

import 'package:gettext_parser/gettext_parser.dart' as gettextParser;

   (data) {
       final gt = new Gettext();

Json file content example:

  "charset": "utf-8",
  "headers": {
    "mime-version": "1.0",
    "content-type": "text/plain; charset=utf-8",
    "content-transfer-encoding": "8bit",
    "language": "es-ES",
    "plural-forms": "nplurals=2; plural=(n!=1);"
  "translations": {
    "": {
      "Hello": {
        "msgid": "Hello",
        "comments": {
           "translator": "Normal string"
        "msgstr": [
      "An apple": {
        "msgid": "1 apple",
        "comments": {
           "translator": "Plural string"
        "msgstr": [
           "una manzana",
           "%d manzanas"

Change locale:

gt.locale = "en_US";

Change default domain:

gt.domain = "types";

Translate messages:


Translate messages with plural forms:

gt.ngettext("An apple", "%d apples", 3); // returns "%d apples"

See example

Usage with flutter #

Use flutter_gettext package.


  • addLocale(Map<String, dynamic> locale, {String domain: 'messages'})
  • addTranslations(String localeName, Map<String, dynamic> translations, {String domain: 'messages'})
  • setCatalog(String localeName, Catalog catalog)
  • gettext(String msgid, {String domain, String context}) → String
  • ngettext(String msgid, String msgplural, int count, {String domain, String context}) → String

1.1.0 #

  • Breaking change. Method addLocale(Map<String, dynamic> locale, {String domain: 'messages'}) changed to addLocale(Map<String, dynamic> locale, {String domain: 'messages'}).
  • Add setCatalog and addLocale methods

1.0.1 #

  • Add changelog and flutter example

1.0.0 #

  • First implementation


import 'dart:convert';
import 'dart:io';

import "package:gettext/gettext.dart";

void main() async {
  final data = await File("./en_US.json").readAsString();

  final gt = new Gettext();

  print(gt.ngettext("An apple", "%d apples", 1));
  print(gt.ngettext("An apple", "%d apples", 3));

Use this package as a library

1. Depend on it

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

  gettext: ^1.1.0+2

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:gettext/gettext.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 Jul 2, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13

Health suggestions

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

Analysis of lib/gettext.dart reported 3 hints:

line 193 col 12: Unnecessary new keyword.

line 195 col 24: Unnecessary new keyword.

line 200 col 31: Unnecessary new keyword.

Maintenance suggestions

Package is getting outdated. (-6.85 points)

The package was last published 55 weeks ago.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
Dev dependencies
test any