fill-pot-po
Advanced tools
Comparing version
{ | ||
"name": "fill-pot-po", | ||
"version": "2.2.0", | ||
"version": "2.2.1", | ||
"description": "Create pre-filled PO files from POT file, using previous PO files.", | ||
@@ -65,3 +65,2 @@ "main": "./dist/index.js", | ||
"babel-plugin-transform-import-meta": "^2.2.0", | ||
"cross-env": "^7.0.3", | ||
"eslint": "^8.45.0", | ||
@@ -68,0 +67,0 @@ "eslint-config-prettier": "^8.8.0", |
185
readme.md
@@ -9,6 +9,7 @@ # fill-pot-po [![GitHub release (latest SemVer)][release-image]][release-url] [![NPM version][npm-image]][npm-url] | ||
> Generate pre-filled PO files from POT file, using source PO files. | ||
> | ||
> *Based on the POT filename or set options, it looks for source PO files. For each PO file, it will create a new one, based on the contents of the POT file. The source PO file is used to fill in the matching translated strings.* | ||
> | ||
> _Based on the POT filename or set options, it looks for source PO files. For each PO file, it will create a new one, based on the contents of the POT file. The source PO file is used to fill in the matching translated strings._ | ||
> | ||
> ✨ **_This package now supports both ESM and CommonJS_** 🎉 | ||
## Use case | ||
@@ -22,3 +23,2 @@ | ||
## Install | ||
@@ -30,3 +30,2 @@ | ||
## Usage | ||
@@ -60,3 +59,3 @@ | ||
#### Example | ||
#### Example (CommonJS) | ||
@@ -66,9 +65,21 @@ ```js | ||
const cb = results => { | ||
// ... | ||
const cb = (results) => { | ||
// ... | ||
}; | ||
fillPotPo( cb, options ); | ||
fillPotPo(cb, options); | ||
``` | ||
#### Example (ESM) | ||
```js | ||
import fillPotPo from 'fill-pot-po'; | ||
const cb = (results) => { | ||
// ... | ||
}; | ||
fillPotPo(cb, options); | ||
``` | ||
### 2. Synchronous | ||
@@ -99,3 +110,3 @@ | ||
#### Example | ||
#### Example (CommonJS) | ||
@@ -106,52 +117,54 @@ ```js | ||
try { | ||
const results = fillPotPoSync( options ); | ||
const results = fillPotPoSync(options); | ||
//... | ||
} catch ( error ) { | ||
console.log( error ); | ||
//... | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
``` | ||
#### Example (ESM) | ||
## Locating PO files for each POT file | ||
For each POT file that is processed, the module will try to locate the proper PO files. | ||
This is the algorithm in pseudo-code: | ||
```js | ||
if ( options.poSources ) { | ||
import { sync as fillPotPoSync } from 'fill-pot-po'; | ||
po_search_glob = options.poSources | ||
try { | ||
const results = fillPotPoSync(options); | ||
} else { | ||
//... | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
``` | ||
source_dir = options.srcDir || pot_file_directory | ||
## Locating PO files for each POT file | ||
if ( options.domainInPOPath ) { | ||
For each POT file that is processed, the module will try to locate the proper PO files. | ||
if ( options.domainFromPOTPath ) { | ||
This is the algorithm in pseudo-code: | ||
// NOTE: If the POT file is an unnamed Vinyl object, an error will be thrown now. | ||
```js | ||
if (options.poSources) { | ||
po_search_glob = options.poSources; | ||
} else { | ||
source_dir = options.srcDir || pot_file_directory; | ||
po_search_glob = `${source_dir}/${pot_file_basename_without_ext}-${any_locale}.po` | ||
if (options.domainInPOPath) { | ||
if (options.domainFromPOTPath) { | ||
// NOTE: If the POT file is an unnamed Vinyl object, an error will be thrown now. | ||
} else { | ||
// NOTE: If options.domain is empty, an error will be thrown now. | ||
po_search_glob = `${source_dir}/${options.domain}-${any_locale}.po` | ||
} | ||
po_search_glob = `${source_dir}/${pot_file_basename_without_ext}-${any_locale}.po`; | ||
} else { | ||
// NOTE: If options.domain is empty, an error will be thrown now. | ||
po_search_glob = `${source_dir}/${any_locale}.po` | ||
po_search_glob = `${source_dir}/${options.domain}-${any_locale}.po`; | ||
} | ||
} else { | ||
po_search_glob = `${source_dir}/${any_locale}.po`; | ||
} | ||
} | ||
// NOTE: For all glob searches, options.srcGlobOptions will be used. | ||
``` | ||
``` | ||
For actual source code, see [**`getPOFilepaths()`**](https://github.com/vHeemstra/fill-pot-po/blob/main/src/shared.js#L50) in **src/shared.js**. | ||
@@ -161,6 +174,6 @@ | ||
## Options | ||
### *Overview of all defaults* | ||
### _Overview of all defaults_ | ||
```js | ||
@@ -193,3 +206,5 @@ { | ||
### potSources | ||
`string|Vinyl|array` | ||
> The POT files to process. Can be a path or glob string, a Vinyl object, an array of strings or an array of Vinyl objects. | ||
@@ -202,9 +217,11 @@ | ||
#### poSources | ||
`string|array` | ||
> The PO source files to use. Can be a path or glob string, or an array of paths/globs. | ||
> | ||
> | ||
> By default, or if falsy, the module will look for PO files with filenames like `{text-domain}-{locale}.po` or `{locale}.po` if [`domainInPOPath`](#domaininpopath) is set to false. | ||
> | ||
> | ||
> `{text-domain}` is either the POT filename or the value set in the [`domain`](#domain) option. | ||
> | ||
> | ||
> See [**Locating PO files for each POT file**](#locating-po-files-for-each-pot-file) for more info. | ||
@@ -215,7 +232,9 @@ | ||
#### srcDir | ||
`string` | ||
> Relative path from current working directory or absolute path to folder where source PO files can be found. | ||
> | ||
> | ||
> By default, the same folder as the POT file will be used. | ||
> | ||
> | ||
> See [**Locating PO files for each POT file**](#locating-po-files-for-each-pot-file) for more info. | ||
@@ -226,7 +245,9 @@ | ||
#### domainInPOPath | ||
`boolean` | ||
> Match source PO files with the text domain name in the filename. | ||
> | ||
> | ||
> For example: `text-domain-en_EN.po` and `text-domain-nl_NL.po`. | ||
> | ||
> | ||
> See [**Locating PO files for each POT file**](#locating-po-files-for-each-pot-file) for more info. | ||
@@ -237,7 +258,9 @@ | ||
#### domainFromPOTPath | ||
`boolean` | ||
> Whether or not to get the text domain from the POT filename (excluding extension). | ||
> | ||
> | ||
> If set to `false` and [`domainInPOPath`](#domaininpopath) is `true`, a text domain must be set using the [`domain`](#domain) option. | ||
> | ||
> | ||
> See [**Locating PO files for each POT file**](#locating-po-files-for-each-pot-file) for more info. | ||
@@ -248,7 +271,9 @@ | ||
#### domain | ||
`string` | ||
> The text domain slug, like `text-domain`. | ||
> | ||
> | ||
> By default this is the POT filename excluding extension and is used to find the right PO source files. | ||
> | ||
> | ||
> See [**Locating PO files for each POT file**](#locating-po-files-for-each-pot-file) for more info. | ||
@@ -259,5 +284,7 @@ | ||
#### srcGlobOptions | ||
`object` | ||
> Glob options used when matching PO source files. | ||
> | ||
> | ||
> See [**Locating PO files for each POT file**](#locating-po-files-for-each-pot-file) for more info. | ||
@@ -270,7 +297,9 @@ | ||
#### returnPOT | ||
`boolean` | ||
> Whether the plugin should return the source POT file(s) (`true`) or the generated PO file(s) (`false`). | ||
> | ||
> | ||
> By default, it will return the generated PO files. | ||
> | ||
> | ||
> _**NOTE**_: If set to `true`, you need to set [`writeFiles`](#writefiles) to `true` as well or else no PO files will be generated and the plugin throws an error. | ||
@@ -281,7 +310,9 @@ | ||
#### writeFiles | ||
`boolean` | ||
> Whether or not to write the newly generated PO files to disk. | ||
> | ||
> | ||
> If you wish to process the results array and content buffers yourself, you could set this to `false`. | ||
> | ||
> | ||
> _**NOTE**_: When using [**gulp-fill-pot-po**](https://github.com/vHeemstra/gulp-fill-pot-po), the default is `false`, since the resulting buffers will probably be `.pipe( dest() )`'d, which writes them to disk instead. | ||
@@ -292,5 +323,7 @@ | ||
#### destDir | ||
`string` | ||
> _Only if [`writeFiles`](#writefiles) is `true`._ | ||
> | ||
> | ||
> Relative path from current working directory or absolute path to the folder where the PO files should be written. | ||
@@ -301,3 +334,5 @@ | ||
#### logResults | ||
`boolean` | ||
> Log results to console. | ||
@@ -310,5 +345,7 @@ | ||
#### wrapLength | ||
`integer` | ||
> Line wrapping length excluding quotation marks. | ||
> | ||
> | ||
> This is forwarded as `foldLength` to [`gettext-parser`](https://github.com/smhg/gettext-parser#compile-po-from-a-translation-object). | ||
@@ -319,5 +356,7 @@ | ||
#### defaultContextAsFallback | ||
`boolean` | ||
> If a string is not found in the PO source file with a certain context, try searching for the same string without a context and use that. | ||
> | ||
> | ||
> A flag comment `#, fuzzy` will be added to signal translators to check the translation. | ||
@@ -328,5 +367,7 @@ | ||
#### appendNonIncludedFromPO | ||
`boolean` | ||
> Append all translated strings from the source PO file that were not in the POT file. | ||
> | ||
> | ||
> A translator comment `# DEPRECATED` will be added to them. | ||
@@ -337,3 +378,5 @@ | ||
#### includePORevisionDate | ||
`boolean` | ||
> Include a `PO-Revision-Date` header to the PO files with the current timestamp. | ||
@@ -344,3 +387,5 @@ | ||
#### includeGenerator | ||
`boolean` | ||
> Include a `X-Generator` header to the PO files. | ||
@@ -350,13 +395,16 @@ | ||
## Results | ||
### Results - Async mode | ||
The first argument of the callback function will be the results array: | ||
#### results[0] | ||
`boolean` True on success, false on error. | ||
#### results[1] (on success) | ||
`array` Array of [Vinyl](https://github.com/gulpjs/vinyl) file objects, depending on the value of [`options.returnPOT`](#returnpot): | ||
<ul><table> | ||
@@ -375,2 +423,3 @@ <tr> | ||
#### results[1] (on error) | ||
`string` Error message. | ||
@@ -381,3 +430,5 @@ | ||
#### On success | ||
`array` Returns an array of [Vinyl](https://github.com/gulpjs/vinyl) file objects, depending on the value of [`options.returnPOT`](#returnpot): | ||
<ul><table> | ||
@@ -396,5 +447,5 @@ <tr> | ||
#### On error | ||
On error, `fillPotPoSync()` will throw an error. | ||
## Related | ||
@@ -406,3 +457,6 @@ | ||
## Extra | ||
- [Guide for migrating your Gulp set-up from CommonJS to ESM](https://gist.github.com/noraj/007a943dc781dc8dd3198a29205bae04) | ||
## License | ||
@@ -414,3 +468,2 @@ | ||
[release-image]: https://img.shields.io/github/v/release/vHeemstra/fill-pot-po?sort=semver&logo=github&logoColor=959DA5&labelColor=444D56 | ||
[ci-url]: https://github.com/vHeemstra/fill-pot-po/actions/workflows/ci_push_on_main.yml | ||
@@ -421,16 +474,12 @@ [ci-image]: https://img.shields.io/github/actions/workflow/status/vHeemstra/fill-pot-po/ci_push_on_main.yml?branch=main&label=lint%20%26%20test&logo=github&logoColor=959DA5&labelColor=444D56 | ||
[ci-image4]: https://img.shields.io/github/workflow/status/vHeemstra/fill-pot-po/Lint%20%7C%20Test%20%7C%20Release?label=lint%20%26%20test&logo=github&logoColor=959DA5&labelColor=444D56 | ||
[coverage-url]: https://coveralls.io/github/vHeemstra/fill-pot-po?branch=main | ||
[coverage-image]: https://img.shields.io/coveralls/github/vHeemstra/fill-pot-po?logo=coveralls&logoColor=959DA5&labelColor=444D56 | ||
[coverage-image_]: https://coveralls.io/repos/github/vHeemstra/fill-pot-po/badge.svg?branch=main | ||
[coverage-url2]: https://codecov.io/gh/vHeemstra/fill-pot-po | ||
[coverage-image2]: https://codecov.io/gh/vHeemstra/fill-pot-po/branch/main/graph/badge.svg?token=sZaKGStMXg | ||
[deps-url]: https://libraries.io/npm/fill-pot-po | ||
[deps-image]: https://img.shields.io/librariesio/release/npm/fill-pot-po?logo=libraries.io&logoColor=959DA5&labelColor=444D56 | ||
[deps-image2]: https://img.shields.io/librariesio/github/vHeemstra/fill-pot-po?logo=libraries.io&logoColor=959DA5&labelColor=444D56 | ||
[npm-url]: https://www.npmjs.com/package/fill-pot-po | ||
[npm-image]: https://img.shields.io/npm/v/fill-pot-po.svg?color=cb0000&labelColor=444D56&logo=data:image/svg+xml;base64,PHN2ZyByb2xlPSJpbWciIHZpZXdCb3g9IjAgMCAyNCAyNCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cGF0aCBmaWxsPSIjOTU5REE1IiBkPSJNMS43NjMgMEMuNzg2IDAgMCAuNzg2IDAgMS43NjN2MjAuNDc0QzAgMjMuMjE0Ljc4NiAyNCAxLjc2MyAyNGgyMC40NzRjLjk3NyAwIDEuNzYzLS43ODYgMS43NjMtMS43NjNWMS43NjNDMjQgLjc4NiAyMy4yMTQgMCAyMi4yMzcgMHpNNS4xMyA1LjMyM2wxMy44MzcuMDE5LS4wMDkgMTMuODM2aC0zLjQ2NGwuMDEtMTAuMzgyaC0zLjQ1NkwxMi4wNCAxOS4xN0g1LjExM3oiPjwvcGF0aD48L3N2Zz4= | ||
[downloads-image]: https://img.shields.io/npm/dm/fill-pot-po.svg?labelColor=444D56&logo=data:image/svg+xml;base64,PHN2ZyByb2xlPSJpbWciIHZpZXdCb3g9IjAgMCAyNCAyNCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cGF0aCBmaWxsPSIjOTU5REE1IiBkPSJNMS43NjMgMEMuNzg2IDAgMCAuNzg2IDAgMS43NjN2MjAuNDc0QzAgMjMuMjE0Ljc4NiAyNCAxLjc2MyAyNGgyMC40NzRjLjk3NyAwIDEuNzYzLS43ODYgMS43NjMtMS43NjNWMS43NjNDMjQgLjc4NiAyMy4yMTQgMCAyMi4yMzcgMHpNNS4xMyA1LjMyM2wxMy44MzcuMDE5LS4wMDkgMTMuODM2aC0zLjQ2NGwuMDEtMTAuMzgyaC0zLjQ1NkwxMi4wNCAxOS4xN0g1LjExM3oiPjwvcGF0aD48L3N2Zz4= |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
44035
1.02%14
-6.67%455
12.07%0
-100%