Skip to content

Commit

Permalink
Move anno-edit type hints entirely into translation JSON (#451)
Browse files Browse the repository at this point in the history
This also adds dynamism so that the translation strings cannot be
requested before they are available.
  • Loading branch information
jgonggrijp committed May 1, 2022
1 parent e2b0e4d commit 9929899
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 29 deletions.
8 changes: 4 additions & 4 deletions frontend/src/i18n/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
"permitted_types_before_list": "This property permits",
"current_type": "Current type:",
"typeHints": {
"integer": "",
"base64Binary": "",
"gYear": "",
"string": ""
"integer": "Include extra leading zeros to force interpretation as an integer type.",
"base64Binary": "Include internal whitespace to force interpretation as base 64 binary data.",
"gYear": "Include time zone information (such as a final “Z”) to force interpretation as a Gregorian year.",
"string": "Start with a space to force interpretation as text or a derived string type."
},
"all_types_permitted": "This property permits any simple type.",
"no_type_matched": "This value does not match the permitted type(s).",
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/i18n/fr/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
"permitted_types_before_list": "This property permits",
"current_type": "Current type:",
"typeHints": {
"integer": "",
"base64Binary": "",
"gYear": "",
"string": ""
"integer": "Include extra leading zeros to force interpretation as an integer type.",
"base64Binary": "Include internal whitespace to force interpretation as base 64 binary data.",
"gYear": "Include time zone information (such as a final “Z”) to force interpretation as a Gregorian year.",
"string": "Start with a space to force interpretation as text or a derived string type."
},
"all_types_permitted": "This property permits any simple type.",
"no_type_matched": "This value does not match the permitted type(s).",
Expand Down
30 changes: 9 additions & 21 deletions frontend/src/item-edit/detected-type-help-view.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { map, extend, propertyOf } from 'lodash';
import { map, extend, fromPairs } from 'lodash';
import * as i18next from 'i18next';

import { CompositeView } from '../core/view';
Expand All @@ -8,26 +8,14 @@ import { xsd } from '../common-rdf/ns';
import ScopedIriLink from './scoped-iri-href-view';
import template from './detected-type-help-template';

const disambiguationHints = {
[xsd.integer]: i18next.t('typeHints.integer',
'Include extra leading zeros to force interpretation ' +
'as an integer type.'
),
[xsd.base64Binary]: i18next.t('typeHints.base64Binary',
'Include internal whitespace to force interpretation ' +
'as base 64 binary data.'
),
[xsd.gYear]: i18next.t('typeHints.gYear',
'Include time zone information (such as a final "Z") to force ' +
'interpretation as a Gregorian year.'
),
[xsd.string]: i18next.t('typeHints.string',
'Start with a space to force interpretation as text or ' +
'a derived string type.'
),
};

const getHint = propertyOf(disambiguationHints);
// i18next.t('typeHints.integer')
// i18next.t('typeHints.base64Binary')
// i18next.t('typeHints.gYear')
// i18next.t('typeHints.string')
const typesWithHints = ['integer', 'base64Binary', 'gYear', 'string'];
const typeAsPair = name => [xsd[name], `typeHints.${name}`];
const disambiguationHints = fromPairs(map(typesWithHints, typeAsPair));
const getHint = type => i18next.t(disambiguationHints[type]);

/**
* This is one of the p.help views used in LinkedItemEditor, to give the user
Expand Down

0 comments on commit 9929899

Please sign in to comment.