nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: i18next/i18next-parser
Pull request #229 (2020-07-22 16:58:14)

fix: Trans element usage with curly braces syntax
### Why am I submitting this PR

If the namespace is provided in curly-braces, it will fall back to the default namespace.
```
<Trans ns={'foo'}>bar</Trans>
```

To avoid this, I added a fix for it and as well a test-case for the curly braces syntax.

### Does it fix an existing ticket?

No



Patch:
diff --git a/src/lexers/jsx-lexer.js b/src/lexers/jsx-lexer.js
index 1ffc28a..62bedf9 100644
--- a/src/lexers/jsx-lexer.js
+++ b/src/lexers/jsx-lexer.js
@@ -61,7 +61,12 @@ export default class JsxLexer extends JavascriptLexer {
       const attribute = node.attributes.properties.find(
         (attr) => attr.name.text === tagName
       )
-      return attribute && attribute.initializer.text
+      if (!attribute) {
+        return undefined
+      }
+      return attribute.initializer.expression
+        ? attribute.initializer.expression.text
+        : attribute.initializer.text
     }
 
     const getKey = (node) => getPropValue(node, this.attr)


Test patch:
diff --git a/test/lexers/jsx-lexer.test.js b/test/lexers/jsx-lexer.test.js
index a52ba87..879f121 100644
--- a/test/lexers/jsx-lexer.test.js
+++ b/test/lexers/jsx-lexer.test.js
@@ -176,6 +176,15 @@ describe('JsxLexer', () => {
       ])
       done()
     })
+
+    it('uses the ns (namespace) prop with curly braces syntax', (done) => {
+      const Lexer = new JsxLexer()
+      const content = `<Trans ns={'foo'}>bar</Trans>`
+      assert.deepEqual(Lexer.extract(content), [
+        { key: 'bar', defaultValue: 'bar', namespace: 'foo' },
+      ])
+      done()
+    })
   })
 
   describe('supports TypeScript', () => {
Repository: i18next/i18next-parser
Pull request #604 (2022-06-14 22:39:23)

Support TypeScript typecasts
### Why am I submitting this PR

Add support for TypeScript typecasts within JSX expressions.

### Does it fix an existing ticket?

Yes - #603

### Checklist

- [X] only relevant code is changed (make a diff before you submit the PR)
- [X] tests are included and pass: `yarn test` (see [details here](https://github.com/i18next/i18next-parser/blob/master/docs/development.md#tests))
- [X] documentation is changed or added



Patch:
diff --git a/src/lexers/jsx-lexer.js b/src/lexers/jsx-lexer.js
index 5a31e76..18251aa 100644
--- a/src/lexers/jsx-lexer.js
+++ b/src/lexers/jsx-lexer.js
@@ -203,7 +203,14 @@ export default class JsxLexer extends JavascriptLexer {
               type: 'text',
               content: '',
             }
-          } else if (child.expression.kind === ts.SyntaxKind.StringLiteral) {
+          }
+
+          // simplify trivial expressions, like TypeScript typecasts
+          if (child.expression.kind === ts.SyntaxKind.AsExpression) {
+            child = child.expression
+          }
+
+          if (child.expression.kind === ts.SyntaxKind.StringLiteral) {
             return {
               type: 'text',
               content: child.expression.text,


Test patch:
diff --git a/test/lexers/jsx-lexer.test.js b/test/lexers/jsx-lexer.test.js
index 8b13057..8345ddd 100644
--- a/test/lexers/jsx-lexer.test.js
+++ b/test/lexers/jsx-lexer.test.js
@@ -341,6 +341,15 @@ describe('JsxLexer', () => {
         done()
       })
 
+      it('erases typecasts', (done) => {
+        const Lexer = new JsxLexer()
+        const content = '<Trans>{{ key: property } as any}</Trans>'
+        assert.deepEqual(Lexer.extract(content), [
+          { key: '{{key}}', defaultValue: '{{key}}' },
+        ])
+        done()
+      })
+
       it('keeps self-closing tags untouched when transSupportBasicHtmlNodes is true', (done) => {
         const Lexer = new JsxLexer({ transSupportBasicHtmlNodes: true })
         const content = '<Trans>a<br />b</Trans>'
Repository: i18next/i18next-parser
Pull request #626 (2022-08-18 11:23:05)

Support custom yaml output options
### Why am I submitting this PR

It would be nice to allow users to have their own settings for yaml output. In fact, I need it for a project :)

### Does it fix an existing ticket?

No

### Checklist

- [x] only relevant code is changed (make a diff before you submit the PR)
- [x] tests are included and pass: `yarn test` (see [details here](https://github.com/i18next/i18next-parser/blob/master/docs/development.md#tests))
- [x] documentation is changed or added



Patch:
diff --git a/README.md b/README.md
index d9073f9..746ce94 100644
--- a/README.md
+++ b/README.md
@@ -222,6 +222,14 @@ export default {
   // If you wish to customize options in internally used i18next instance, you can define an object with any
   // configuration property supported by i18next (https://www.i18next.com/overview/configuration-options).
   // { compatibilityJSON: 'v3' } can be used to generate v3 compatible plurals.
+
+  yamlOptions: null,
+  // If you wish to customize options for yaml output, you can define an object here.
+  // Configuration options are here (https://github.com/nodeca/js-yaml#dump-object---options-).
+  // Example:
+  // {
+  //   lineWidth: -1,
+  // }
 }
 ```
 
diff --git a/src/transform.js b/src/transform.js
index 1e160ad..07ba0c7 100644
--- a/src/transform.js
+++ b/src/transform.js
@@ -41,6 +41,7 @@ export default class i18nTransform extends Transform {
       skipDefaultValues: false,
       customValueTemplate: null,
       failOnWarnings: false,
+      yamlOptions: null,
     }
 
     this.options = { ...this.defaults, ...options }
@@ -365,6 +366,7 @@ export default class i18nTransform extends Transform {
     if (path.endsWith('yml')) {
       text = yaml.dump(contents, {
         indent: this.options.indentation,
+        ...this.options.yamlOptions,
       })
     } else {
       text = JSON.stringify(contents, null, this.options.indentation) + '\n'


Test patch:
diff --git a/test/parser.test.js b/test/parser.test.js
index 9b79362..130251b 100644
--- a/test/parser.test.js
+++ b/test/parser.test.js
@@ -1395,6 +1395,33 @@ describe('parser', () => {
       i18nextParser.end(fakeFile)
     })
 
+    it('supports custom output configuration for yml', (done) => {
+      let result
+      const i18nextParser = new i18nTransform({
+        output: 'locales/$LOCALE/$NAMESPACE.yml',
+        yamlOptions: {
+          forceQuotes: true,
+          quotingType: '"',
+        },
+      })
+      const fakeFile = new Vinyl({
+        contents: Buffer.from("t('first', 'test')"),
+        path: 'file.js',
+      })
+
+      i18nextParser.on('data', (file) => {
+        if (file.relative.endsWith(path.normalize('en/translation.yml'))) {
+          result = file.contents.toString('utf8')
+        }
+      })
+      i18nextParser.once('end', () => {
+        assert.equal(result.replace(/\r\n/g, '\n'), 'first: "test"\n')
+        done()
+      })
+
+      i18nextParser.end(fakeFile)
+    })
+
     it('writes non-breaking space output to yml', (done) => {
       let result
       const i18nextParser = new i18nTransform({
Repository: i18next/i18next-parser
Pull request #804 (2023-04-15 00:46:37)

add support for user-defined component functions
### Why am I submitting this PR

To fix the issue describe in #803. This PR adds support for user-defined component functions to the JsxLexer.

### Does it fix an existing ticket?

Yes #803

### Checklist

- [x] only relevant code is changed (make a diff before you submit the PR)
- [x] tests are included and pass: `yarn test` (see [details here](https://github.com/i18next/i18next-parser/blob/master/docs/development.md#tests))
- [x] documentation is changed or added



Patch:
diff --git a/README.md b/README.md
index 3c4ef3b..322b287 100644
--- a/README.md
+++ b/README.md
@@ -263,6 +263,7 @@ Default configuration:
   jsx: [{
     lexer: 'JsxLexer',
     attr: 'i18nKey', // Attribute for the keys
+    componentFunctions: ['Trans'], // Array of components to match
   }],
 }
 ```
diff --git a/src/lexers/jsx-lexer.js b/src/lexers/jsx-lexer.js
index 830ef0a..11dfd5f 100644
--- a/src/lexers/jsx-lexer.js
+++ b/src/lexers/jsx-lexer.js
@@ -6,6 +6,7 @@ export default class JsxLexer extends JavascriptLexer {
   constructor(options = {}) {
     super(options)
 
+    this.componentFunctions = options.componentFunctions || ['Trans']
     this.transSupportBasicHtmlNodes =
       options.transSupportBasicHtmlNodes || false
     this.transKeepBasicHtmlNodesFor = options.transKeepBasicHtmlNodesFor || [
@@ -88,7 +89,7 @@ export default class JsxLexer extends JavascriptLexer {
 
     const getKey = (node) => getPropValue(node, this.attr)
 
-    if (tagNode.tagName.text === 'Trans') {
+    if (this.componentFunctions.includes(tagNode.tagName.text)) {
       const entry = {}
       entry.key = getKey(tagNode)
 


Test patch:
diff --git a/test/lexers/jsx-lexer.test.js b/test/lexers/jsx-lexer.test.js
index b5de066..b75ff98 100644
--- a/test/lexers/jsx-lexer.test.js
+++ b/test/lexers/jsx-lexer.test.js
@@ -132,6 +132,23 @@ describe('JsxLexer', () => {
       done()
     })
 
+    it('extracts keys from user-defined components', (done) => {
+      const Lexer = new JsxLexer({
+        componentFunctions: ['Translate', 'FooBar'],
+      })
+      const content = `<div>
+      <Translate i18nKey="something">Something to translate.</Translate>
+      <NotSupported i18nKey="jkl">asdf</NotSupported>
+      <FooBar i18nKey="asdf">Lorum Ipsum</FooBar>
+      </div>
+      `
+      assert.deepEqual(Lexer.extract(content), [
+        { key: 'something', defaultValue: 'Something to translate.' },
+        { key: 'asdf', defaultValue: 'Lorum Ipsum' },
+      ])
+      done()
+    })
+
     it('extracts keys from single line comments', (done) => {
       const Lexer = new JsxLexer()
       const content = `
Repository: i18next/i18next-parser
Pull request #817 (2023-05-06 11:28:24)

Add support for string concatenation in default values
### Why am I submitting this PR

When using a string as the second argument to the `t` function, it would be interpreted as `defaultValue` for that key. However, sometimes that string becomes too long and you need to split it into multiple lines. Using template literals has its downsides as it preserves indents and new lines. Thus, the easiest thing to do would be to use string concatenation, e.g.:
```js
i18next.t(
  'key',
  'This is a very long string that needs to be split into multiple ' +
  'lines bla bla bla bla bla bla bla bla bla'
)
```

### Does it fix an existing ticket?

Not that I'm aware of.

### Checklist

- [X] only relevant code is changed (make a diff before you submit the PR)
- [X] tests are included and pass: `yarn test` (see [details here](https://github.com/i18next/i18next-parser/blob/master/docs/development.md#tests))
- [ ] documentation is changed or added



Patch:
diff --git a/src/lexers/javascript-lexer.js b/src/lexers/javascript-lexer.js
index b75c117..22740ae 100644
--- a/src/lexers/javascript-lexer.js
+++ b/src/lexers/javascript-lexer.js
@@ -256,7 +256,7 @@ export default class JavascriptLexer extends BaseLexer {
 
       let optionsArgument = node.arguments.shift()
 
-      // Second argument could be a string default value
+      // Second argument could be a (concatenated) string default value
       if (
         optionsArgument &&
         (optionsArgument.kind === ts.SyntaxKind.StringLiteral ||
@@ -264,6 +264,20 @@ export default class JavascriptLexer extends BaseLexer {
       ) {
         entry.defaultValue = optionsArgument.text
         optionsArgument = node.arguments.shift()
+      } else if (
+        optionsArgument &&
+        optionsArgument.kind === ts.SyntaxKind.BinaryExpression
+      ) {
+        const concatenatedString = this.concatenateString(optionsArgument)
+        if (!concatenatedString) {
+          this.emit(
+            'warning',
+            `Default value is not a string literal: ${optionsArgument.text}`
+          )
+          return null
+        }
+        entry.defaultValue = concatenatedString
+        optionsArgument = node.arguments.shift()
       }
 
       if (


Test patch:
diff --git a/test/lexers/javascript-lexer.test.js b/test/lexers/javascript-lexer.test.js
index 491ed83..508ddf4 100644
--- a/test/lexers/javascript-lexer.test.js
+++ b/test/lexers/javascript-lexer.test.js
@@ -27,6 +27,15 @@ describe('JavascriptLexer', () => {
     done()
   })
 
+  it('extracts the second argument string concatenation as defaultValue', (done) => {
+    const Lexer = new JavascriptLexer()
+    const content = 'i18n.t("first", "bla" + "bla" + "bla")'
+    assert.deepEqual(Lexer.extract(content), [
+      { key: 'first', defaultValue: 'blablabla' },
+    ])
+    done()
+  })
+
   it('extracts the defaultValue/context options', (done) => {
     const Lexer = new JavascriptLexer()
     const content = 'i18n.t("first", {defaultValue: "foo", context: \'bar\'})'
Repository: i18next/i18next-parser
Pull request #825 (2023-05-26 19:39:00)

feat: allow to disable plural handling
### Why am I submitting this PR

Adds possibility to disable keys generation for plurals by setting `pluralSeparator: false`.

### Does it fix an existing ticket?

closes https://github.com/i18next/i18next-parser/issues/463

### Checklist

- [x] only relevant code is changed (make a diff before you submit the PR)
- [x] tests are included and pass: `yarn test` (see [details here](https://github.com/i18next/i18next-parser/blob/master/docs/development.md#tests))
- [x] documentation is changed or added



Patch:
diff --git a/README.md b/README.md
index 3c04b97..668b960 100644
--- a/README.md
+++ b/README.md
@@ -178,6 +178,7 @@ export default {
   pluralSeparator: '_',
   // Plural separator used in your translation keys
   // If you want to use plain english keys, separators such as `_` might conflict. You might want to set `pluralSeparator` to a different string that does not occur in your keys.
+  // If you don't want to generate keys for plurals (for example, in case you are using ICU format), set `pluralSeparator: false`.
 
   input: undefined,
   // An array of globs that describe where to look for source files
diff --git a/src/transform.js b/src/transform.js
index 3f692a6..b549a5d 100644
--- a/src/transform.js
+++ b/src/transform.js
@@ -191,7 +191,10 @@ export default class i18nTransform extends Transform {
 
       // generates plurals according to i18next rules: key_zero, key_one, key_two, key_few, key_many and key_other
       for (const entry of this.entries) {
-        if (entry.count !== undefined) {
+        if (
+          this.options.pluralSeparator !== false &&
+          entry.count !== undefined
+        ) {
           this.i18next.services.pluralResolver
             .getSuffixes(locale, { ordinal: entry.ordinal })
             .forEach((suffix) => {


Test patch:
diff --git a/test/parser.test.js b/test/parser.test.js
index 52e2b06..1d58540 100644
--- a/test/parser.test.js
+++ b/test/parser.test.js
@@ -652,6 +652,31 @@ describe('parser', () => {
     i18nextParser.end(fakeFile)
   })
 
+  it('ignores plural values in existing catalog if pluralSeparator set to false', (done) => {
+    let result
+    const i18nextParser = new i18nTransform({
+      pluralSeparator: false,
+    })
+    const fakeFile = new Vinyl({
+      contents: Buffer.from("t('test {{count}}', { count: 1 })"),
+      path: 'file.js',
+    })
+
+    i18nextParser.on('data', (file) => {
+      if (file.relative.endsWith(enLibraryPath)) {
+        result = JSON.parse(file.contents)
+      }
+    })
+    i18nextParser.once('end', () => {
+      assert.deepEqual(result, {
+        'test {{count}}': '',
+      })
+      done()
+    })
+
+    i18nextParser.end(fakeFile)
+  })
+
   it('retrieves plural values in existing catalog', (done) => {
     let result
     const i18nextParser = new i18nTransform({
Repository: i18next/i18next-parser
Pull request #862 (2023-07-19 21:54:24)

Skip extracting dynamic children in Trans components
### Why am I submitting this PR
While working on localizing our project, we found that components with the `i18nIsDynamicList` property weren't being extracted correctly. See https://react.i18next.com/latest/trans-component#using-with-lists-v10.5.0 for the documentation on this prop.

### Does it fix an existing ticket?
No.

### Checklist

- [x] only relevant code is changed (make a diff before you submit the PR)
- [x] tests are included and pass: `yarn test` (see [details here](https://github.com/i18next/i18next-parser/blob/master/docs/development.md#tests))
- [ ] documentation is changed or added



Patch:
diff --git a/src/lexers/jsx-lexer.js b/src/lexers/jsx-lexer.js
index 11dfd5f..d5ce6d4 100644
--- a/src/lexers/jsx-lexer.js
+++ b/src/lexers/jsx-lexer.js
@@ -208,9 +208,14 @@ export default class JsxLexer extends JavascriptLexer {
           const element = child.openingElement || child
           const name = element.tagName.escapedText
           const isBasic = !element.attributes.properties.length
+          const hasDynamicChildren = element.attributes.properties.find(
+            (prop) => prop.name.escapedText === 'i18nIsDynamicList'
+          )
           return {
             type: 'tag',
-            children: this.parseChildren(child.children, sourceText),
+            children: hasDynamicChildren
+              ? []
+              : this.parseChildren(child.children, sourceText),
             name,
             isBasic,
             selfClosing: child.kind === ts.SyntaxKind.JsxSelfClosingElement,


Test patch:
diff --git a/test/lexers/jsx-lexer.test.js b/test/lexers/jsx-lexer.test.js
index b75ff98..b84e45f 100644
--- a/test/lexers/jsx-lexer.test.js
+++ b/test/lexers/jsx-lexer.test.js
@@ -218,6 +218,17 @@ describe('JsxLexer', () => {
       done()
     })
 
+    it('skips dynamic children', (done) => {
+      const Lexer = new JsxLexer()
+      const content =
+        '<Trans>My dogs are named: <ul i18nIsDynamicList>{["rupert", "max"].map(dog => (<li>{dog}</li>))}</ul></Trans>'
+      assert.equal(
+        Lexer.extract(content)[0].defaultValue,
+        'My dogs are named: <1></1>'
+      )
+      done()
+    })
+
     it('erases comment expressions', (done) => {
       const Lexer = new JsxLexer()
       const content = '<Trans>{/* some comment */}Some Content</Trans>'