Kolibri: interpolate variables into translation strings

Created on 23 Mar 2017  路  7Comments  路  Source: learningequality/kolibri

Translation strings must not be concatenated with variables - the variables need to be interpolated using ICU message syntax

example 1:

      deleteConfirmation: 'Are you sure you want to remove ',
      from: ' from ',
      still: 'You can still access this account from ',

example 2:

      deleteConfirmation: 'Are you sure you want to delete ',
bug

All 7 comments

@indirectlylit Is there a list I can reference to tackle some of these?

nope, but searching vue files for these two regexes find some strings with leading and trailing space:

  • : ' .+',
  • : '.+ ',

results:

Searching 126 files for ": ' .+'," (regex)

/Users/d/Projects/learning_equality/repos/kolibri/kolibri/plugins/coach/assets/src/views/attempt-log-list/index.vue:
   50        today: 'Today',
   51        yesterday: 'Yesterday',
   52:       daysAgo: ' { daysElapsed } days ago',
   53        question: 'Question { questionNumber, number }',
   54      },

/Users/d/Projects/learning_equality/repos/kolibri/kolibri/plugins/management/assets/src/views/class-edit-page/user-remove-modal.vue:
   47        // confirmation messages
   48        deleteConfirmation: 'Are you sure you want to remove ',
   49:       from: ' from ',
   50        still: 'You can still access this account from ',
   51        users: 'Users',

2 matches across 2 files


Searching 126 files for ": '.+ '," (regex)

/Users/d/Projects/learning_equality/repos/kolibri/kolibri/plugins/management/assets/src/views/class-edit-page/user-remove-modal.vue:
   46        cancel: 'Cancel',
   47        // confirmation messages
   48:       deleteConfirmation: 'Are you sure you want to remove ',
   49:       from: ' from ',
   50:       still: 'You can still access this account from ',
   51        users: 'Users',
   52      },

/Users/d/Projects/learning_equality/repos/kolibri/kolibri/plugins/management/assets/src/views/manage-class-page/class-delete-modal.vue:
   47        description: 'Users will only be removed from the class and are still accessible from the "Users" tab.',
   48        // confirmation messages
   49:       deleteConfirmation: 'Are you sure you want to delete ',
   50      },
   51      components: {

4 matches across 2 files

I'd say fixing those is good enough for this task. We could potentially do a deeper audit of all translated strings but I think that'd be overkill at the moment.

I'm not finding a way to get this done on most of these strings while also including HTML (making string bold)

Should I interpolate and forget about HTML formatting, or leave them be? @indirectlylit

Found a hacky way to do this.

There is a $trHtml function for this purpose - however it's potentially risky and I think we should avoid using it when possible. (https://trello.com/c/gHONGfCU/795-question-is-trhtml-a-potential-source-of-bugs-or-security-holes)

@indirectlylit I had said that it doesn't do anything differently. That was wrong.

I avoided its use though! And the way I used it, the translator never sees any of the HTML. Let me know what you think; I was kind of iffy on it.

Good to avoid it if possible, definitely,at least until we can come up with some better sanitisation on string import.

Can't find anything else with provided regexs. Will assume this is good for now.

Was this page helpful?
0 / 5 - 0 ratings