Skip to content

Commit

Permalink
Use newlines instead of commas to separate translated aliases (re: #3)
Browse files Browse the repository at this point in the history
Strip whitespace between search terms
  • Loading branch information
quincylvania committed Dec 10, 2020
1 parent 83e0c22 commit b44adb3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
10 changes: 7 additions & 3 deletions lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,10 @@ function generatePresets(dataDir, tstrings, searchableFieldIDs, listReusedIcons)
};
delete preset.name;

if (preset.aliases) tstrings.presets[id].aliases = preset.aliases.join(',');
if (preset.aliases) tstrings.presets[id].aliases = preset.aliases.map(t => t.trim()).filter(Boolean).join('\n');
delete preset.aliases;

tstrings.presets[id].terms = (preset.terms || []).join(',');
tstrings.presets[id].terms = (preset.terms || []).map(t => t.trim()).filter(Boolean).join(',');

This comment has been minimized.

Copy link
@westnordost

westnordost Dec 11, 2020

Wouldn't it be

  1. consistent and
  2. make sense for the same reason as for the aliases (but at a lesser degree)

to also use the newline for terms?

Of course, this requires once to execute some script that replaces all "," with "\n" for all translation files and re-upload them to transifex.

One way or the other, data consumers which parse the translation files will either need to be adapted to split by "\n" instead of ",", or the build process which puts the translation files into dist already splits them up and puts them into an array.

This comment has been minimized.

Copy link
@quincylvania

quincylvania Dec 11, 2020

Author Contributor

Consistency was the reason I used a comma in the first place for aliases. It would be nice for terms to be the same, but I don't know how much it matters. Writing a re-upload script seems like a lot of work with little practical benefit. Maybe one day.

or the build process which puts the translation files into dist already splits them up and puts them into an array.

This is probably what we should do. It'll make the file size slightly bigger, but it's weird to make clients parse this themselves.

delete preset.terms;

if (preset.moreFields) {
Expand Down Expand Up @@ -392,7 +392,11 @@ function generateTranslations(fields, presets, tstrings, searchableFieldIDs) {
let keys = Object.keys(tags);

if (keys.length) {
yamlPreset['name#'] = keys.map(k => `${k}=${tags[k]}`).join(' + ') + ' (translate with one or more comma-separated names)';
yamlPreset['name#'] = keys.map(k => `${k}=${tags[k]}`).join(' + ');
if (yamlPreset.aliases) {
yamlPreset['name#'] += '\\n\\n' + yamlPreset.aliases.split('\n').join('\\n');
}
yamlPreset['name#'] += '\\n\\nTranslate the primary name. Optionally, add equivalent synonyms on newlines in order of preference (press the Return key).';
}

if (preset.searchable !== false) {
Expand Down
6 changes: 3 additions & 3 deletions lib/translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,15 @@ function fetchTranslations(options) {
let preset = presets[key];

if (preset.name) {
let names = preset.name.split(',').map(s => s.trim());
let names = preset.name.split('\n').map(s => s.trim()).filter(Boolean);
preset.name = preset.name[0];
if (names.length > 1) {
preset.aliases = names.slice(1).join(',');
preset.aliases = names.slice(1).join('\n');
}
}

if (!preset.terms) continue;
preset.terms = preset.terms.replace(/<.*>/, '').trim();
preset.terms = preset.terms.replace(/<.*>/, '').split(',').map(s => s.trim()).filter(Boolean).join(',');
if (!preset.terms) {
delete preset.terms;
if (!Object.keys(preset).length) {
Expand Down

0 comments on commit b44adb3

Please sign in to comment.