Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Lexical error on line 1. Unrecognized text. #49

Closed
tombertrand opened this issue Jul 7, 2016 · 7 comments
Closed

Error: Lexical error on line 1. Unrecognized text. #49

tombertrand opened this issue Jul 7, 2016 · 7 comments
Labels

Comments

@tombertrand
Copy link

tombertrand commented Jul 7, 2016

Working on Mac when creating folders it also creates a bunch of extra invisible files such as .DS_Store, these files then gets included by the xgettext package and obviously throws an error because they are invalid handlebars files.

Could the -D parameter references and parse only .hbs or .handlebars files?

Had to clear extra files using the commands described inside mikeal/tako#4 but then as soon as something is modified, the file gets created again

// Of course create an extention-language mapping array for the other supported languages: Swig, Volt and EJS
if (options.directory) {
  readdirp({root: options.directory, fileFilter: ['*.hbs', '*.handlebars']}, function(err, res) {
    if (err) {
      throw err;
    }

    parseFiles(res.files.map(function (file) {
      return file.fullPath;
    }), output);
  });
} else {
@smhg
Copy link
Collaborator

smhg commented Jul 7, 2016

Could you post the whole command (including parameters) which you use to run xgettext-template?
I haven't used it much outside of Poedit.

@tombertrand
Copy link
Author

//package.json
"scripts": {
    "po": "xgettext-template -L Handlebars -D views -o en.po --from-code utf8 --force-po"
},

screen shot 2016-07-07 at 5 43 28 pm

@smhg
Copy link
Collaborator

smhg commented Jul 8, 2016

2 thoughts on this:

  • xgettext-template should match xgettext as close as possible (although still lacking many parameters). There doesn't seem to be an input-file filtering option in xgettext as far as I can tell. The way you filter is by piping a selection of files. Can you give this a try?
  • The -D parameter has the wrong effect. It should only change the root directory, not provide all files in that directory as input. I'll track this in a separate issue.

@smhg smhg added the question label Jul 8, 2016
@smhg
Copy link
Collaborator

smhg commented Jul 8, 2016

I had some issues with the command from the SO above, but this worked for me:

find views -name "*.handlebars" \
| xargs xgettext-template -L Handlebars --from-code utf8 --force-po -o en.po

(I guess you should remove the slash and write it as one line in package.json)

@tombertrand
Copy link
Author

tombertrand commented Jul 8, 2016

Indeed the above command worked just fine! Thanks!

"scripts": {
    "po": "find views -name '*.handlebars' | xargs xgettext-template -L Handlebars --from-code utf8 --force-po -o en.po"
},

@smhg
Copy link
Collaborator

smhg commented Jul 9, 2016

You're welcome!
Last step would be to test this cross-platform (Windows) and probably replace find/xargs with JS alternatives. Feel free to add the result should you go that way.

@smhg smhg closed this as completed Jul 9, 2016
@tombertrand
Copy link
Author

tombertrand commented Jul 12, 2016

I've ended up using a Grunt task to handle the .pot / .po / .json transformations. Here is the sample of code:

// node_modules required:
// xargs - for compatibility
// po2json - generate json file from a .po to be used by Jed
// grunt-shell - execute shell commands

// tasks/po.js
var locales = ["en_US", "es_US", "fr_CA"];

module.exports = {
    shell: {
        options: {
            failOnError: true,
            preferLocal: true
        },
        xgettext: {
            command: "find js/receipt/templates -name '*.hbs' | xargs xgettext-template -L Handlebars -o js/receipt/po/ref.pot --from-code utf8 -j --force-po"
        },
        msgmerge: {
            command: locales.map(function (locale) {
                return "msgmerge js/receipt/po/" + locale + ".po js/receipt/po/ref.pot -U\n";
            }).join("")
        },
        po2json: {
            command: locales.map(function (locale) {
                 return "po2json js/receipt/po/" + locale + ".po js/receipt/json/" + locale + ".json -f jed1.x -p true\n";
            }).join("")
        }
    }
}

//Gruntfile.js
grunt.registerTask(
    'po', [
        'shell:xgettext',
        'shell:msgmerge',
        'shell:po2json'
    ]
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants