Giter Club home page Giter Club logo

ember-i18n-to-intl-migrator's Introduction

ember-i18n-to-intl-migrator

A node script to migrate both your translation files and service injections to ember-intl

Installation

Run the following command in your terminal:

npm install ember-i18n-intl-migrator -g

or alternatively with yarn:

yarn global add ember-i18n-intl-migrator

Usage

To transform the translation files run:

ember-i18n-intl-migrator # default conversion to json
ember-i18n-intl-migrator --type=yaml

To also run the codemod that will replace i18n: service() by intl: service() (and it's usages), you first have to install jscodeshift with:

npm install -g jscodeshift

Then you can run the codemod with:

jscodeshift -t https://raw.githubusercontent.com/DockYard/ember-i18n-to-intl-migrator/master/lib/codemod.js app/

ember-i18n-to-intl-migrator's People

Contributors

caltor avatar cibernox avatar iezer avatar jonpitch avatar snewcomer avatar walter avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ember-i18n-to-intl-migrator's Issues

Replace translationMacro

conversion tool doesn't do anything to fix the line that reads import { translationMacro as t } from 'ember-i18n';

TypeError: Cannot convert undefined or null to object

yarn global add ember-i18n-intl-migrator
ember-i18n-intl-migrator

TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at isPluralObject (/home/mifrill/.config/yarn/global/node_modules/ember-i18n-intl-migrator/lib/translation-transform.js:70:17)
    at Object.keys.forEach.key (/home/mifrill/.config/yarn/global/node_modules/ember-i18n-intl-migrator/lib/translation-transform.js:50:45)
    at Array.forEach (<anonymous>)
    at walk (/home/mifrill/.config/yarn/global/node_modules/ember-i18n-intl-migrator/lib/translation-transform.js:40:20)
    at Object.keys.forEach.key (/home/mifrill/.config/yarn/global/node_modules/ember-i18n-intl-migrator/lib/translation-transform.js:56:18)
    at Array.forEach (<anonymous>)
    at walk (/home/mifrill/.config/yarn/global/node_modules/ember-i18n-intl-migrator/lib/translation-transform.js:40:20)
    at Object.keys.forEach.key (/home/mifrill/.config/yarn/global/node_modules/ember-i18n-intl-migrator/lib/translation-transform.js:56:18)
    at Array.forEach (<anonymous>)

    "ember-source": "~2.14.0",

    "ember-i18n": "4.5.0",
    "ember-i18n-cp-validations": "^3.1.0",
    "ember-i18n-errors": "0.2.0",

quotes around yaml keys with dot notation

Right now, the transformation will result in a key like this if in yaml format.

foo.bar-baz: "Hey there"

This seems valid, but I'm not sure if we should add quotes around the key.

"foo.bar-baz": "Hey there"

YAML conversion issues

I'll use a single ember-i18n translation file as an example

Characteristics of the file; it's deeply nested at times, has lots of comments, but is well laid out

Here's a snippet from /app/locales/en-au/translations.js

export default {
  "common": {
    "comingSoon": "Coming Soon",
    "assetDetails": "Asset Details",
    "close": "Close",
    "history": "History",
    "live": "Live",
    "pagination": {
      "prev": "Prev",
      "next": "Next",
      "pageOf": "Page {{number}} of {{total}}"
    },
    "loading": "Loading",
    "sectionBreak": "Section Break",
    "helpText": "Help Text",
    "emptyChart": "No data to display",
    "na": "N/A",
    "all": "All",
    "on": "On",
    "off": "Off",
    "disabled": "Disabled",
    "mobile": "Mobile",
    "tablet": "Tablet",
    "ignition": "Ignition",
    "bearings": {
      "n": {
        "code": "N",
        "full": "North"
      },
      "s": {
        "code": "S",
        "full": "South"
      },
      "e": {
        "code": "E",
        "full": "East"
      },
      "w": {
        "code": "W",
        "full": "West"
      },
      "ne": {
        "code": "NE",
        "full": "North-East"
      },
      "nw": {
        "code": "NW",
        "full": "North-West"
      },
      "se": {
        "code": "SE",
        "full": "South-East"
      },
      "sw": {
        "code": "SW",
        "full": "South-West"
      }
    }
  }
}

I decided that yaml is probably a better option for flexibility, so I ran this command
ember-i18n-intl-migrator --type=yaml

That gives an output file of /translations/en-au.json

The first problem I noticed is that the file is .json rather than .yml. Opening the file it looks like it has converted to YAML (output below) but I have a few suggestions;

  • Comments don't seem to have been transferred across, is it possible to do this?
  • My nests are now mostly on one line, after reaching the 2nd level, is it possible to keep the nesting?
  • Translation text in the YAML file uses quotes "" for all translations that are multiple words, whereas it uses no quotes for single words. Can we use quotes also for single words?

/translations/en-au.json

common:
    comingSoon: 'Coming Soon'
    assetDetails: 'Asset Details'
    close: Close
    history: History
    live: Live
    pagination: {prev: Prev, next: Next, pageOf: 'Page {number} of {total}'}
    loading: Loading
    sectionBreak: 'Section Break'
    helpText: 'Help Text'
    emptyChart: 'No data to display'
    na: N/A
    all: All
    on: On
    off: Off
    disabled: Disabled
    mobile: Mobile
    tablet: Tablet
    ignition: Ignition
    bearings: {n: {code: N, full: North}, s: {code: S, full: South}, e: {code: E, full: East}, w: {code: W, full: West}, ne: {code: NE, full: North-East}, nw: {code: NW, full: North-West}, se: {code: SE, full: South-East}, sw: {code: SW, full: South-West}}

SyntaxError: Unexpected identifier when running script

Running the script produces this error:

SyntaxError: Unexpected identifier
    at new Function (<anonymous>)
    at Object.locales.forEach (/home/skidder/.nvm/versions/node/v10.11.0/lib/node_modules/ember-i18n-intl-migrator/lib/translation-transform.js:12:15)
    at Array.forEach (<anonymous>)
    at module.exports (/home/skidder/.nvm/versions/node/v10.11.0/lib/node_modules/ember-i18n-intl-migrator/lib/translation-transform.js:10:11)
    at Object.<anonymous> (/home/skidder/.nvm/versions/node/v10.11.0/lib/node_modules/ember-i18n-intl-migrator/bin/ember-i18n-intl-migrator.js:10:3)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)

Note: touchy about code in translations.js files

FYI for other users having trouble, you should strip as much logic from your translation files as possible before running this. In my case I hit a snag because I was relying on a global (requireNode from ember-electron) and calling a utility function to merge some language-agnostic constants from another file. Before taking that out I was getting errors like this:

SyntaxError: Unexpected identifier
    at new Function (<anonymous>)
    at Object.locales.forEach (/home/user/.nvm/versions/node/v10.13.0/lib/node_modules/ember-i18n-intl-migrator/lib/translation-transform.js:12:15)
...

The codemode i18n -> intl is removing too many spaces

Hi, thanks for this codemod, unfortunately it triggers too many undesired changes, ex:

export default Component.extend({

  i18n: inject(),

  prop: 'value',

  prop2: 'value2'

Will be rewritten as:

export default Component.extend({
  intl: inject(),
  prop: 'value',
  prop2: 'value2'

which is kind of annoying.

Cannot use import statement outside a module

After installing the module with sudo npm install ember-i18n-intl-migrator -g, I get the following error when running it (no args):

SyntaxError: Cannot use import statement outside a module
    at new Function (<anonymous>)
    at Object.<anonymous> (/usr/local/lib/node_modules/ember-i18n-intl-migrator/lib/translation-transform.js:12:15)
    at Array.forEach (<anonymous>)
    at module.exports (/usr/local/lib/node_modules/ember-i18n-intl-migrator/lib/translation-transform.js:10:11)
    at Object.<anonymous> (/usr/local/lib/node_modules/ember-i18n-intl-migrator/bin/ember-i18n-intl-migrator.js:10:3)
    at Module._compile (internal/modules/cjs/loader.js:971:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1011:10)
    at Module.load (internal/modules/cjs/loader.js:822:32)
    at Function.Module._load (internal/modules/cjs/loader.js:730:14)
    at Function.Module.runMain (internal/modules/cjs/loader.js:1051:12)

I tried changing directories, from the base ember folder, but just got:

Error: ENOENT: no such file or directory, scandir 'app/locales'

Which makes sense. Thus, I must be in the correct directory, but something else is going wrong.
This also happens when I install the module as a local user, along ember-i18n (not globally), and run it from the node_modules folder.

Node Version: v13.0.1
Operating System: Ubuntu 18.04.3 LTS

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.