grunt-json2php

[![npm](http://img.shields.io/npm/v/grunt-excel-vocabulary.svg?style=flat-square)](https://www.npmjs.com/package/grunt-excel-vocabulary) [![npm](http://img.shields.io/npm/l/grunt-excel-vocabulary.svg?style=flat-square)](http://opensource.org/licenses/MIT)

Usage no npm install needed!

<script type="module">
  import gruntJson2php from 'https://cdn.skypack.dev/grunt-json2php';
</script>

README

npm npm Dependency Status devDependency Status Build Status Coverage Status

grunt-json2php

Grunt plugin for convert json file to php file with associative array.

Getting Started

This plugin requires Grunt ~0.4.x

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-excel-vocabulary --save

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

grunt.loadNpmTasks('grunt-json2php');

The "json2php" task

Overview

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

grunt.initConfig({
  json2php: {
    options: {
      // Task-specific options go here.
    },
    your_target: {
      // Target-specific file lists and/or options go here.
    },
  },
});

Options

options.root

Type: String Default value: process.cwd()

if you need put your translation excel files somewhere in file system, not in process.cwd

options.compress

Type: String Default value: false

<?php

return array("a" => "b", "c" => "d");

?>

if true then all whitespaces will remove

<?php

return array("a"=>"b","c"=>"d");

?>

options.cover

Type: Function Default:

cover: function (phpArrayString, destFilePath) {
    return '<?php\n\nreturn ' + phpArrayString + ';\n\n?>';
}

add php file cover.

Usage Examples

Default Options

In this example, the default options are used to do something with whatever. So if the testing file has the content Testing and the 123 file had the content 1 2 3, the generated result would be Testing, 1 2 3.

grunt.initConfig({
  json2php: {
    convert: {
      expand: true,
      cwd: 'examples',
      dest: '.tmp',
      ext: '.php',
      src: [
        '**/*.json'
      ]
    }
  },
});