Simplify translation strings

This commit is contained in:
Bryan Housel
2018-12-22 12:12:28 -05:00
parent f7150004c0
commit 3785ffb154
5 changed files with 990 additions and 1102 deletions
+23 -31
View File
@@ -23,7 +23,13 @@ var dispatch = d3_dispatch('loaded');
var _krCache;
var _krZoom = 14;
var apibase = 'https://www.keepright.at/';
var defaultRuleset = [0,30,40,50,70,90,100,110,120,130,150,160,170,180,191,192,193,194,195,196,197,198,201,202,203,204,205,206,207,208,210,220,231,232,270,281,282,283,284,285,291,292,293,294,295,296,297,298,311,312,313,320,350,370,380,401,402,411,412,413];
var defaultRuleset = [
0, 30, 40, 50, 70, 90, 100, 110, 120, 130, 150, 160, 170, 180,
191, 192, 193, 194, 195, 196, 197, 198, 201, 202, 203, 204, 205,
206, 207, 208, 210, 220, 231, 232, 270, 281, 282, 283, 284, 285,
291, 292 ,293, 294, 295, 296, 297, 298, 311, 312, 313, 320, 350,
370, 380, 401, 402, 411, 412, 413
];
function abortRequest(i) {
@@ -62,45 +68,34 @@ function updateRtree(item, replace) {
}
function tokenReplacements(datum) {
if (!(datum instanceof krError)) return;
function tokenReplacements(d) {
if (!(d instanceof krError)) return;
var replacements = {};
var html_re = new RegExp(/<\/[a-z][\s\S]*>/);
var commonEntities = ['node', 'way', 'relation', 'highway', 'cycleway', 'waterway', 'riverbank'];
var errorType;
var errorTemplate;
var errorDescription;
var errorRegex;
var errorMatch;
// find the matching template from the error schema
errorType = '_' + datum.error_type;
errorTemplate = errorTypes.errors[errorType] || errorTypes.warnings[errorType];
var errorTemplate = errorTypes[d.error_type];
if (!errorTemplate) return;
// some descriptions are just fixed text
if (!('regex' in errorTemplate)) return;
if (!errorTemplate.regex) return;
// regex pattern should match description with variable details captured as groups
errorDescription = datum.description;
errorRegex = new RegExp(errorTemplate.description);
errorMatch = errorRegex.exec(errorDescription);
var errorDescription = d.description;
var errorRegex = new RegExp(errorTemplate.description);
var errorMatch = errorRegex.exec(errorDescription);
if (!errorMatch) {
// TODO: Remove, for regex dev testing
console.log('Unmatched:', errorType, errorDescription, errorRegex);
console.log('Unmatched:', d.error_type, d.description, errorRegex);
return;
}
errorMatch.forEach(function(group, index) {
for (var i = 1; i < errorMatch.length; i++) { // skip first
var group = errorMatch[i];
var idType;
// index 0 is the whole match, skip it
if (!index) return;
// link IDs if present in the group
idType = 'IDs' in errorTemplate ? errorTemplate.IDs[index-1] : '';
idType = 'IDs' in errorTemplate ? errorTemplate.IDs[i-1] : '';
if (idType && group) {
group = parseError(group, idType);
} else if (html_re.test(group)) {
@@ -108,13 +103,8 @@ function tokenReplacements(datum) {
group = '\\' + group + '\\';
}
// translate common words (e.g. node, way, relation)
if (commonEntities.includes(group)) {
group = t('QA.keepRight.entities.' + group);
}
replacements['var' + index] = group;
});
replacements[i-1] = group;
}
return replacements;
}
@@ -122,7 +112,9 @@ function tokenReplacements(datum) {
function parseError(group, idType) {
function fillPlaceholder(d) { return '<span><a class="kr_error_description-id">' + d + '</a></span>'; }
function fillPlaceholder(d) {
return '<span><a class="kr_error_description-id">' + d + '</a></span>';
}
// arbitrary node list of form: #ID, #ID, #ID...
function parseError211(list) {
+32 -53
View File
@@ -5,43 +5,22 @@ import { t } from '../util/locale';
export function uiKeepRightDetails(context) {
var stringBase = 'QA.keepRight.errorTypes.';
var _error;
var _template;
var _templateErrorType;
var _category;
var _categoryElements;
var _parent_error_type;
var _titleBase;
function initDetails() {
_parent_error_type = '';
if (errorTypes.errors['_' + _error.error_type]) {
_templateErrorType = '_' + _error.error_type;
_template = errorTypes.errors[_templateErrorType];
_category = 'errors';
} else if (errorTypes.warnings[_templateErrorType]) {
_template = errorTypes.warnings[_templateErrorType];
_category = 'warnings';
} else { return; }
// if there is a parent, save it's error type
_categoryElements = errorTypes[_category];
var base_error_type = (Math.round(_error.error_type / 10) * 10).toString();
if ((_categoryElements['_' + base_error_type]) && (base_error_type !== _error.error_type) ) {
_parent_error_type = '_' + base_error_type;
}
_titleBase = 'QA.keepRight.errorTypes.' + _category + '.';
}
function keepRightDetails(selection) {
if (!_error || !_error.error_type) return;
if (!_error) return;
initDetails();
if (!_template) return;
var errorType = _error.error_type;
var template = errorTypes[errorType];
if (!template) return;
// if there is a parent, save its error type e.g.:
// Error 191 = "highway-highway"
// Error 190 = "intersections without junctions" (parent)
var parentErrorType = (Math.floor(errorType / 10) * 10).toString();
var parentTemplate = errorTypes[parentErrorType];
if (!parentTemplate) return;
var details = selection.selectAll('.kr_error-details')
@@ -57,30 +36,24 @@ export function uiKeepRightDetails(context) {
.append('div')
.attr('class', 'kr_error-details kr_error-details-container');
// title
var title = detailsEnter
var titleEnter = detailsEnter
.append('div')
.attr('class', 'kr_error-details-title');
title.append('h4')
titleEnter
.append('h4')
.text(function() { return t('QA.keepRight.detail_title'); });
title.append('div')
titleEnter
.append('div')
.text(function() {
var title = '';
// if this is a subtype, append it's parent title
if (_parent_error_type) {
title = t(_titleBase + _parent_error_type + '.title') + ': \n';
var result;
try {
result = t(stringBase + errorType + '.title');
} catch (e) {
result = t(stringBase + parentErrorType + '.title');
}
// append title
if (_error.error_type) {
title += t(_titleBase + _templateErrorType + '.title');
}
return title;
return result;
});
@@ -97,17 +70,23 @@ export function uiKeepRightDetails(context) {
.append('div')
.attr('class', 'kr_error-details-description-text')
.html(function(d) {
return t(_titleBase + _templateErrorType + '.description', d.replacements);
var result;
try {
result = t(stringBase + errorType + '.description', d.replacements);
} catch (e) {
result = t(stringBase + parentErrorType + '.description');
}
return result;
});
description.selectAll('.kr_error_description-id')
.on('click', function() { clickLink(context, this.text); });
function clickLink(context, id) {
function clickLink(context, entityID) {
d3_event.preventDefault();
context.layers().layer('osm').enabled(true);
context.zoomToEntity(id);
context.zoomToEntity(entityID);
}
}