Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-gettext-extractor

Package Overview
Dependencies
Maintainers
4
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-gettext-extractor - npm Package Compare versions

Comparing version 4.0.0 to 4.1.0

28

index.js

@@ -66,9 +66,27 @@ var utils = require('./utils');

if (typeof fileName === 'function') {
fileName = fileName(this.file);
}
if (!fileName) {
return;
}
if (fileName !== currentFileName) {
currentFileName = fileName;
data = {
charset: 'UTF-8',
headers: headers,
translations: { context: {} },
};
if (fs.existsSync(fileName)) {
const fileContents = fs.readFileSync(fileName, 'utf8');
data = gettextParser.po.parse(fileContents);
data.headers = {
...(data.headers || {}),
...headers,
};
data.translations.context = data.translations.context || {};
} else {
data = {
charset: 'UTF-8',
headers: headers,
translations: { context: {} },
};
}

@@ -75,0 +93,0 @@ headers['plural-forms'] = headers['plural-forms']

2

package.json
{
"name": "babel-gettext-extractor",
"version": "4.0.0",
"version": "4.1.0",
"description": " Extract gettext string with babel",

@@ -5,0 +5,0 @@ "main": "index.js",

[![Build Status](https://travis-ci.org/mozilla/babel-gettext-extractor.svg?branch=master)](https://travis-ci.org/mozilla/babel-gettext-extractor)
[![npm version](https://img.shields.io/npm/v/babel-gettext-extractor.svg)](https://www.npmjs.com/package/babel-gettext-extractor)

@@ -42,3 +43,3 @@ # babel-gettext-extractor

"functionNames": <Object>,
"fileName": <String>,
"fileName": <String|Function>,
"baseDirectory": <String>,

@@ -75,4 +76,25 @@ "stripTemplateLiteralIndent": <Boolean>

The filename where the end result is placed.
The filename where the end result is placed. If you supply a function, it will receive the current file babel is working
on and you can return the full path to where you want to save your translation template for this particular file.
example:
```javascript
[
require("babel-gettext-extractor"),
{
fileName: (file) => {
const sourceFile = file.opts.sourceFileName;
if (/^node_modules\//.test(sourceFile)) {
return false;
}
return sourceFile
.split(/[\/\\.]/)
.filter(name => !['src', 'packages', 'js'].includes(name))
.slice(0, 2)
.join('-') + '-template.pot';
},
},
]
```
### baseDirectory ###

@@ -79,0 +101,0 @@

@@ -7,3 +7,2 @@ var assert = require('assert');

describe('babel-gettext-extractor', function() {

@@ -163,3 +162,37 @@ describe('#extract()', function() {

});
it('Should decide on a filename dynamically', function() {
const code = '_t("Dynamic Filenames")';
var result = babel.transform(code, {
plugins: [
[plugin, {
functionNames: {
_t: ['msgid'],
},
fileName: (file) => 'test/' + file.opts.sourceFileName + '-dynamic-filename.po',
}],
],
});
assert(!!result);
var content = fs.readFileSync('./test/unknown-dynamic-filename.po');
assert(content.indexOf('msgid "Dynamic Filenames"') !== -1);
});
it('Should skip a file if the dynamic filename is false', function() {
const code = '_t("Dynamic Filenames")';
var result = babel.transform(code, {
plugins: [
[plugin, {
functionNames: {
_t: ['msgid'],
},
fileName: () => false,
}],
],
});
assert(!!result);
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc