potgen v3.0.2
PotGen
PotGen simplifies the generation of .pot, .po, and .mo files, allowing you to create translation files quickly and efficiently, thus facilitating the localization of your projects.
Table of Contents
Installation
To install PotGen, use npm:
npm install potgenAdditional Requirements
To create .mo files, you need to have GetText installed. If you are on Windows, you can download and install GetText from:
GetText for Windows
- GetText V 0.14.4 here
Usage
Create Configuration File
If PotGen does not generate a pot.json file in the root of your project after installation, create it manually with the following configuration:
{
"sourcePattern": "**/*.{php,js}",
"destFile": "languages/${domain}.pot",
"package": "Default Package",
"domain": "default-domain",
"lastTranslator": "DEFAULT TRANSLATOR",
"bugReport": "https://default.com/bugs",
"version": "1.0.0",
"createPoFiles": false,
"languages": ["es_ES", "es_PE", "ru_RU"]
}Configure Script in package.json
Add the following scripts to your package.json file:
"scripts": {
"pot": "node node_modules/potgen/pot.js",
"watch": "gulp --gulpfile pogen.js default",
"po2mo": "gulp --gulpfile pogen.js po2mo",
"lang": "gulp --gulpfile pogen.js lang"
}Run PotGen
Depending on the configuration of createPoFiles in pot.json:
If createPoFiles is true:
npm run potExpected output:
Generating .pot file...
Successfully generated .pot file: default-domain.pot ✓
Generating .po files for: es_PE
.po file generated successfully: default-domain-es_PE.po ✓
Generating .po files for: ru_RU
.po file generated successfully: default-domain-ru_RU.po ✓If createPoFiles is false:
npm run potExpected output:
Generating .pot file...
Successfully generated .pot file: default-domain.pot ✓Using Gulp
You can use the following commands to manage translation files:
gulp --gulpfile pogen.js defaultor
npm run watchThis will start the monitoring process for changes in .po files:
Starting 'default'...
Watching for changes in .po filesTo convert .po files to .mo:
gulp --gulpfile pogen.js po2moor
npm run po2moExpected output:
Starting 'po2mo'...
Converting .po files to .mo
Conversion completed ✓To convert .po files for a specific language:
gulp --gulpfile pogen.js lang --lang=es_PEor
npm run lang -- --lang=es_PEExpected output:
Starting 'lang'...
Converting files matching es_PE.po
Files found matching es_PE.po
Conversion completed for es_PE.po ✓Configuration
| Option | Description | Default Value |
|---|---|---|
sourcePattern | Glob pattern that specifies the files to search | **/*.{php,js} |
destFile | Path and name of the destination .pot file. | languages/${domain}.pot |
package | Name of the package. | Default Package |
domain | Domain for the .pot file. | default-domain |
lastTranslator | Information about the last translator. | DEFAULT TRANSLATOR |
bugReport | URL for reporting bugs. | https://default.com/bugs |
version | Version of the translation file. | 1.0.0 |
createPoFiles | true: Generates .po files in addition to the .pot file false: Only generates the .pot file. | false |
languages | List of languages for generating .po files. You can add more as needed. | ["es_ES", "es_PE", "ru_RU"] |
Features
- 🚀 Automatically generates
.pot,.po, and.mofiles for WordPress plugins and themes. - 💻 Supports PHP and JavaScript files.
- ⚙️ Configurable through a simple JSON file.
- 🔠 Handles multiple WordPress translation functions (
__,_e,_n,_x). - ⚠️ Warns about undefined domains.
- 🔄 Options to convert
.pofiles to.moand generate.pofiles based on configuration.
Recent Updates
Changes Implemented in Version 3.0.0
- Generation of
.poand.moFiles: PotGen can now also generate.pofiles and convert them to.mo, in addition to.potfiles. - Improved Gulp Support: New Gulp commands have been added to watch for changes, convert
.pofiles to.mo, and generate files for specific languages. - Configuration Update: The
createPoFilesoption now allows you to specify whether to generate.pofiles along with the.potfile.
Changes Implemented in Version 2.0.0
- HTML Handling and Format Markers: Improved handling of HTML tags and format markers in translation strings.
- HTML Links and Multiple Markers: Correct escaping of quotes in HTML attributes.
- Long Texts with HTML and Apostrophes: Proper handling of apostrophes and long texts with HTML.
- HTML Entity Decoding: Decoding of HTML entities for better readability in
.potfiles.
Contribution
If you find any issues or have suggestions for improvements, feel free to open an issue or submit a pull request in the PotGen repository on GitHub.
Donate
If you appreciate this project and would like to support its ongoing development, you can make a donation through Ko-fi. Your support is greatly appreciated!
License
PotGen is licensed under the MIT License