GithubHelp home page GithubHelp logo

ondrasak / grunt-po2json-angular-translate Goto Github PK

View Code? Open in Web Editor NEW

This project forked from angular-translate/grunt-po2json-angular-translate

0.0 1.0 2.0 53 KB

grunt plugin to convert po to an angular-translate format

License: MIT License

JavaScript 100.00%

grunt-po2json-angular-translate's Introduction

grunt-po2json-angular-translate

grunt plugin to convert po to angangular-translate format

Getting Started

This plugin requires Grunt ~0.4.2

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-po2json-angular-translate --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-po2json-angular-translate');

The "po2json_angular_translate" task

Overview

In your project's Gruntfile, add a section named po2json_angular_translate to the data object passed into grunt.initConfig().

grunt.initConfig({
  po2json_angular_translate: {
  options: {
     pretty: false,
     upperCaseId : false
    },
    your_target: {
                 files: {
                     'tmp/dest.json' : ['test/fixtures/*.po'], // This will generate a single json file with all the specified strings
                     'tmp/dest' : ['test/fixtures/*.po'] //this will create several json files with its own strings
                        }
    },
  },
});

Options

options.pretty

Type: Boolean Default value: false If you want to pretty print the result

options.upperCaseId

Type: Boolean Default value: false If you want to convert the ids to uppercase

options.cleanPrevStrings

Type: Boolean Default value: false It will remove all the previous generated files on the destination specified before creating the new ones.

options.enableAltPlaceholders

Type: Boolean Default value: true It enables you to use alternative placeholders format, it defaults with {foo}.

options.placeholderStructure

Type: Array Default value: ['{','}'] Here you can set your own placeholder structure. Notice that you must specify a closing mark.

Usage Examples

Default Options

grunt.initConfig({
  po2json_angular_translate: {
    options: {},
    files: {
      'dest/': ['src/**/*.po'],
    },
  },
});

Pluralization

To get the angular-translate format of pluralizations, we need to have a po file with the standard format, which would look something like:

msgid "button/save-change"
msgid_plural "button/save-changes"
msgstr[0] "Save %d Change"
msgstr[1] "Save %d Changes"

Which will be converted into:

  {"button/save-change": "Save {PLURALIZE, plural, offset:1 =2{# Change} other{# Changes}}"}

Please, for complex language pluralizations, like in German, I would recommend to make a quick scann, to make sure that everything makes sense.

Be sure that both (singular and plural) contain the same length, otherwise, the output won't be the desired one

Not

msgid "button/save-change"
msgid_plural "button/save-changes"
msgstr[0] "Save %d Change"
msgstr[1] "Save Changes"

Note that the placeholder for numbers should be: %d, so the plugin understands that there goes a number pluralization.

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

Release History

0.0.1 First basic functionality. Just convert the po files into JSON objects compatible with angular-translate

Features planned

  • Support for messageFormat interpolations
  • Improve pluralizations.
  • Posibility to escape special characters
  • Option to generate the result either as a json file, as it is done currently, or directly in angular format
  • Add support for flags, fuzzy strings, etc.
  • Organize by namespaces a json file.

Changelog

v 0.0.3

  • Added support for creation of a single .json file with strings beloging to several po files
  • Added option " cleanPrevStrings: true ", it will clean all the previous generated files before creating the new ones. Defaults false.
  • Added variable replacement. Always it finds the standard format (%d) it will be replaced, and it allows you to specify a custom format as well.

grunt-po2json-angular-translate's People

Contributors

danielavalero avatar ddomonkos avatar ondrasak avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.