Coder Social home page Coder Social logo

hu19891110 / makepot-1 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from papnkukn/makepot

0.0 2.0 0.0 8 KB

Extract localized strings from .php files and create a .pot file for translation. WordPress compatible. No dependencies.

License: MIT License

JavaScript 97.71% PHP 2.29%

makepot-1's Introduction

Introduction

Extract localized strings from .php files and create a .pot file for translation. WordPress compatible. No dependencies.

Note: this library covers 90% of everyday cases. However, some complex strings may be missing in the output - add those strings manually.

Getting Started

Install the package:

npm install -g makepot

Usage:

makepot path/to/php/folder path/to/out/folder

Command Line

Usage:
  makepot [options] <php-dir> <out-dir>

Options:
  --help          Print this message
  --json          Save extracted strings in JSON file
  --force         Force overwrite file
  --verbose       Enable detailed logging
  --version       Print version number

Examples:
  makepot --version
  makepot --verbose . lang
  makepot --json wp-content/themes wp-content/languages

Using as library

var makepot = require('makepot');
makepot({ dir: 'path/to/php/folder' }, function(error, result) {
  if (error) return console.error(error);
  console.log(result.data);
  console.log(result.pot[0].name);
  console.log(result.pot[0].content);
});

console.log(result.data);

[
  {
    "hits": 65,
    "file": "includes/ajax.php",
    "data": [
      {
        "func": "__",
        "name": "wp_theme",
        "args": [ " ago" ],
        "match": "__(' ago', 'wp_theme')",
        "line": 43,
        "file": "includes/ajax.php"
      },
      {
        "func": "__",
        "name": "wp_theme",
        "args": [ " about " ],
        "match": "__(' about ', 'wp_theme')",
        "line": 51,
        "file": "includes/ajax.php"
      },
      ...
      {
        "func": "_e",
        "name": "wp_theme",
        "args": [ "Demo settings will import \"theme options\", \"widgets\", \"revolution slider\" and \"visual composer templates\"" ],
        "match": "_e('Demo settings will import \"theme options\", \"widgets\", \"revolution slider\" and \"visual composer templates\"', 'wp_theme')",
        "line": 135,
        "file": "includes/ajax.php"
      }
    ]
  },
  ...
]

console.log(result.pot[0].name);

wp_theme

console.log(result.pot[0].content);

msgid ""
msgstr ""
"Language: en\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: makepot.js 0.3.0\n"

#: includes/ajax.php:43
msgid " ago"
msgstr ""

#: includes/ajax.php:51
msgid " about "
msgstr ""

...

#: includes/ajax.php:135
msgid "Demo settings will import \"theme options\", \"widgets\", \"revolution slider\" and \"visual composer templates\""
msgstr ""

makepot-1's People

Watchers

hadi avatar  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.