jamesarosen/ember-i18n

Interpolating quotes

BlueCutOfficial opened this issue · 2 comments

Hi,
I am meeting an issue with ember-i18n in a specific use case. I need to use {{this syntaxe}}} to replace a part of a translation that corresponds to a "complete title" more than a simple word.
I realized that ember-i18n is not able to interpolate quotes correctly:

// default-compiler-test.js

// This returns L'apostrophe is used in French
test('it interpolates the apostrophe', function(assert) {
  const result = compileAndEval('{{apostrophe}} is used in French', { apostrophe: 'L\'apostrophe'});
  assert.equal(result, 'L\'apostrophe is used in French');
});

// This returns "double quotes\"""
test('it interpolates the quotes', function(assert) {
  const result = compileAndEval('{{quotes}}', { quotes: '"double quotes"'});
  assert.equal(result, '"double quotes"');
});

// This is working :)
test('it interpolates the French quotes', function(assert) {
  const result = compileAndEval('{{quotes}} are used in French', { quotes: '«These quotes»'});
  assert.equal(result, '«These quotes» are used in French');
});

Finding a workaround is not really hard but it would be nice to have a cleaner solution directly implemented in ember-i18n :)

' is the HTML encoding of '. Have you tried

t('...', { apostrophe: safeString('L\'apostrophe') })

Thank you for safeString trail. I am not sure where it supposes to come from but by looking for it I reached this result:

import { htmlSafe } from '@ember/string';
t('...', { apostrophe: htmlSafe('L\'apostrophe') })

And it's working 🎊