0

In the FilePond we should localize text with the use of attributes. For example labelMaxFileSize="Maximum file size is {filesize}". In the project we are using js-lingui. So actual translation would look like this:

labelMaxFileSize: i18n._(t`Maximum file size is {filesize}`),

Problem: both FilePond and lingui use {} chars to mark variables. And this causing problem. How it may be fixed?

SilentImp
  • 1,865
  • 1
  • 18
  • 28
  • Looked around the lingui docs, but couldn't find it. I would expect there should some way to tell lingui that your sentence contains literal characters. Maybe escaping them works? ```labelMaxFileSize: i18n._(t`Maximum file size is \{filesize\}`),``` – Rik Feb 19 '19 at 07:21
  • @rik sure, I have tried that. I don't get error if I do it like that: ```i18n._(t`Maximum file size is \\{filesize\\}`)```. But it actually doesn't translate anything that way also. – SilentImp Feb 19 '19 at 09:04
  • Error text: `TypeError: Cannot read property 'filesize' of undefined` — it came from /node_modules/@lingui/core/cjs/core.development.js:134 I suppose that lingui think that filesize is lingui variable and expect filesize value should be passed. But it's should be passed by filephond. – SilentImp Feb 19 '19 at 09:08
  • I would think this isn't the first time that someone tries to translate something that has a `{foo}` block in it. – Rik Feb 19 '19 at 09:27
  • @rik same here, but I can't google the solution yet. There is two possible way to solve this: 1. somehow escape {} — failing at the moment. 2. setup symbols FilePond using to mark variable. Look like there is no way to do it at the moment. – SilentImp Feb 19 '19 at 09:38
  • Actually I have found pretty nit solution, but still far from ideal: ```javascript function printf(fmt, ...args) { return fmt.split('%%').reduce((aggregate, chunk, i) => aggregate + chunk + (args[i] || ''), ''); } // … labelMaxTotalFileSize: printf(i18n._(t`Maximum total file size is %% `), '{filesize}'), ``` – SilentImp Feb 19 '19 at 16:05

0 Answers0