lint: Add i18n linter rule for invalid i18n.t tags.

After seeing yet another contributor accidentally try to add i18n tags
that don't work using this pattern, it's time for a lint rule.
This commit is contained in:
Tim Abbott 2020-05-27 14:03:16 -07:00
parent 86d4861c2d
commit d4dfeb57fd
6 changed files with 12 additions and 12 deletions

View File

@ -225,7 +225,7 @@ run_test('validate', () => {
reminder.is_deferred_delivery = () => true;
compose.validate();
assert.equal($('#sending-indicator').html(), 'translated: Scheduling...');
assert.equal($('#sending-indicator').text(), 'translated: Scheduling...');
reminder.is_deferred_delivery = noop;
add_content_to_compose_box();

View File

@ -45,8 +45,9 @@ function add_alert_word(alert_word) {
url: '/json/users/me/alert_words',
data: {alert_words: JSON.stringify(words_to_be_added)},
success: function () {
const message = "Alert word \"" + words_to_be_added + "\" added successfully!";
update_alert_word_status(i18n.t(message), false);
const message = i18n.t('Alert word "__word__" added successfully!',
{word: words_to_be_added[0]});
update_alert_word_status(message, false);
$('#create_alert_word_name').val('');
},
error: function () {

View File

@ -2,7 +2,7 @@
Toggle x = components.toggle({
selected: Integer selected_index,
values: Array<Object> [
{ label: i18n.t(String title) }
{ label: i18n.t("String title") }
],
callback: function () {
// .. on value change.

View File

@ -75,10 +75,7 @@ exports.clear_all_everyone_warnings = function () {
};
function show_sending_indicator(whats_happening) {
if (whats_happening === undefined) {
whats_happening = 'Sending...';
}
$("#sending-indicator").html(i18n.t(whats_happening));
$("#sending-indicator").text(whats_happening);
$("#sending-indicator").show();
}
@ -647,9 +644,9 @@ exports.validate = function () {
$("#compose-send-button").attr('disabled', 'disabled').blur();
const message_content = compose_state.message_content();
if (reminder.is_deferred_delivery(message_content)) {
show_sending_indicator('Scheduling...');
show_sending_indicator(i18n.t('Scheduling...'));
} else {
show_sending_indicator();
show_sending_indicator(i18n.t('Sending...'));
}
if (/^\s*$/.test(message_content)) {

View File

@ -64,8 +64,7 @@ function is_local_part(value, element) {
}
exports.type_id_to_string = function (type_id) {
const name = page_params.bot_types.find(bot_type => bot_type.type_id === type_id).name;
return i18n.t(name);
return page_params.bot_types.find(bot_type => bot_type.type_id === type_id).name;
};
exports.render_bots = function () {

View File

@ -125,6 +125,9 @@ js_rules = RuleList(
'description': 'i18n string should not be a multiline string'},
{'pattern': r'''i18n\.t\(['"].+?['"]\s*\+''',
'description': 'Do not concatenate arguments within i18n.t()'},
{'pattern': r'''i18n\.t\([a-zA-Z]''',
'exclude': {'static/js/templates.js'},
'description': 'Do not pass a variable into i18n.t; it will not be exported to Transifex for translation.'},
{'pattern': r'i18n\.t\(.+\).*\+',
'description': 'Do not concatenate i18n strings'},
{'pattern': r'\+.*i18n\.t\(.+\)',