Skip to content

Commit

Permalink
Fix area/instrument i18n in EntityLink
Browse files Browse the repository at this point in the history
Fixes a couple issues in the previous code:

 * It should've been checking for areas, not artists. Artists don't have
   translated names (not counting aliases), but areas which are
   countries do. You can see this is the behavior of the original TT
   macros, too: areas and instruments default to l_name for their
   content.

 * We don't serialize any l_name property. We have to get the translated
   name from the appropriate gettext domain.
  • Loading branch information
mwiencek committed Mar 17, 2018
1 parent 026190c commit 75252bf
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
8 changes: 6 additions & 2 deletions root/static/scripts/common/components/EntityLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const React = require('react');
const Frag = require('../../../../components/Frag');
const {ENTITIES, AREA_TYPE_COUNTRY} = require('../constants');
const {l} = require('../i18n');
const {l_countries} = require('../i18n/countries');
const {l_instruments} = require('../i18n/instruments');
const bracketed = require('../utility/bracketed');
const entityHref = require('../utility/entityHref');
const formatDatePeriod = require('../utility/formatDatePeriod');
Expand Down Expand Up @@ -103,8 +105,10 @@ const EntityLink = (props = {}) => {
hover = entity.sort_name + bracketed(comment);
}

if (entityType === 'artist' || entityType === 'instrument') {
content = content || entity.l_name;
if (entityType === 'area') {
content = content || l_countries(entity.name);
} else if (entityType === 'instrument') {
content = content || l_instruments(entity.name);
}

content = content || ko.unwrap(entity.name);
Expand Down
20 changes: 20 additions & 0 deletions root/static/scripts/common/i18n/countries.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* @flow
* Copyright (C) 2018 MetaBrainz Foundation
*
* This file is part of MusicBrainz, the open internet music database,
* and is licensed under the GPL version 2, or (at your option) any
* later version: http://www.gnu.org/licenses/gpl-2.0.txt
*/

import wrapGettext from './wrapGettext';

const l_countries = wrapGettext('dgettext', 'countries');
const ln_countries = wrapGettext('dngettext', 'countries');
const lp_countries = wrapGettext('dpgettext', 'countries');

export {
l_countries,
ln_countries,
lp_countries,
};
20 changes: 20 additions & 0 deletions root/static/scripts/common/i18n/instruments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* @flow
* Copyright (C) 2018 MetaBrainz Foundation
*
* This file is part of MusicBrainz, the open internet music database,
* and is licensed under the GPL version 2, or (at your option) any
* later version: http://www.gnu.org/licenses/gpl-2.0.txt
*/

import wrapGettext from './wrapGettext';

const l_instruments = wrapGettext('dgettext', 'instruments');
const ln_instruments = wrapGettext('dngettext', 'instruments');
const lp_instruments = wrapGettext('dpgettext', 'instruments');

export {
l_instruments,
ln_instruments,
lp_instruments,
};

0 comments on commit 75252bf

Please sign in to comment.