From 530f55dc4018457939c729ddce0f82b6183abc71 Mon Sep 17 00:00:00 2001 From: Cory Chaplin Date: Tue, 25 Mar 2014 15:33:51 +0100 Subject: [PATCH] More work on text themes. Splitting translation and text themes, adding nick/ident/host and channel support. Work in progress. --- client/assets/text_themes/default.json | 37 +++++++++++++++++--------- client/src/helpers/utils.js | 9 +++++++ client/src/models/channel.js | 10 +++---- client/src/models/member.js | 4 +++ client/src/models/network.js | 37 +++++++++++++------------- client/src/translations/en-gb.po | 20 +++++++------- client/src/translations/fr.po | 20 +++++++------- client/src/views/channel.js | 2 +- client/src/views/texttheme.js | 25 ++++++++++------- 9 files changed, 97 insertions(+), 67 deletions(-) diff --git a/client/assets/text_themes/default.json b/client/assets/text_themes/default.json index 7879be3..a0577e0 100644 --- a/client/assets/text_themes/default.json +++ b/client/assets/text_themes/default.json @@ -1,15 +1,26 @@ { - "client_models_channel_join": "%C3== %I%T", - "client_models_channel_part": "%C5== %I%T", - "client_models_channel_quit": "%C5== %I%T", - "client_models_channel_kicked": "%C5== %I%T", - "client_models_channel_selfkick": "%C5== %I%T", - "client_models_network_badpassword": "%C3== %I%T", - "client_models_network_mode": "%C3== %I%T", - "client_models_network_selfmode": "%C3== %I%T", - "client_models_network_banned": "%C3== %I%T", - "client_models_network_channel_badkey": "%C3== %I%T", - "client_models_network_channel_inviteonly": "%C3== %I%T", - "client_models_network_channel_limitreached": "%C3== %I%T", - "client_models_network_nickname_alreadyinuse": "%C3== %I%T" + "client_models_channel_join": "== %N %T", + "client_models_channel_part": "== %N %T", + "client_models_channel_quit": "== %N %T", + "client_models_channel_kicked": "== %N %T", + "client_models_channel_selfkick": "== %T", + "client_models_network_badpassword": "== %T", + "client_views_channel_topic": "== %T", + "client_models_network_mode": "== %N %T", + "client_models_network_selfmode": "== %N %T", + "client_models_network_banned": "== %T", + "client_models_network_channel_badkey": "== %T", + "client_models_network_channel_inviteonly": "== %C %T", + "client_models_network_channel_limitreached": "== %C %T", + "client_models_network_nickname_alreadyinuse": "== %T", + "client_models_network_channel_invalid_name": "== %C %T", + "client_models_network_disconnected": "%T", + "client_models_network_topic": "%T", + "client_models_network_channels": "%T", + "client_models_network_idle_and_signon": "%T", + "client_models_network_away": "%T", + "client_models_network_server": "%T", + "client_models_network_idle": "%T", + "client_models_network_nickname_notfound": "%T", + "client_models_network_nickname_changed": "%N %T" } \ No newline at end of file diff --git a/client/src/helpers/utils.js b/client/src/helpers/utils.js index 8931c87..f9384c3 100644 --- a/client/src/helpers/utils.js +++ b/client/src/helpers/utils.js @@ -501,4 +501,13 @@ function parseISO8601(str) { return _date; } +} + +// Simplyfy the translation syntax +function translateText(string_id, params) { + return _kiwi.global.i18n.translate(string_id).fetch(params); +} +// Simplyfy the text styling syntax +function styleText(string_id, params) { + return _kiwi.global.text_theme.styleText(string_id, params); } \ No newline at end of file diff --git a/client/src/models/channel.js b/client/src/models/channel.js index 04e1ed6..bb4f835 100644 --- a/client/src/models/channel.js +++ b/client/src/models/channel.js @@ -22,7 +22,7 @@ _kiwi.model.Channel = _kiwi.model.Panel.extend({ return; } - this.addMsg(' ', _kiwi.global.text_theme.styleText('client_models_channel_join', [member.displayNick(true)]), 'action join', {time: options.kiwi.time}); + this.addMsg(' ', styleText('client_models_channel_join', {'%M': member.getMemberMask(), '%T': translateText('client_models_channel_join'), '%C': name}), 'action join', {time: options.kiwi.time}); }, this); members.bind("remove", function (member, members, options) { @@ -30,20 +30,20 @@ _kiwi.model.Channel = _kiwi.model.Panel.extend({ var msg = (options.kiwi.message) ? '(' + options.kiwi.message + ')' : ''; if (options.kiwi.type === 'quit' && show_message) { - this.addMsg(' ', _kiwi.global.text_theme.styleText('client_models_channel_quit', [member.displayNick(true)], msg), 'action quit', {time: options.kiwi.time}); + this.addMsg(' ', styleText('client_models_channel_quit', {'%M': member.getMemberMask(), '%T': translateText('client_models_channel_quit', [msg]), '%C': name}), 'action quit', {time: options.kiwi.time}); } else if (options.kiwi.type === 'kick') { if (!options.kiwi.current_user_kicked) { //If user kicked someone, show the message regardless of settings. if (show_message || options.kiwi.current_user_initiated) { - this.addMsg(' ', _kiwi.global.text_theme.styleText('client_models_channel_kicked', [member.displayNick(true), options.kiwi.by, msg]), 'action kick', {time: options.kiwi.time}); + this.addMsg(' ', styleText('client_models_channel_kicked', {'%M': member.getMemberMask(), '%T': translateText('client_models_channel_kicked', [options.kiwi.by, msg]), '%C': name}), 'action kick', {time: options.kiwi.time}); } } else { - this.addMsg(' ', _kiwi.global.text_theme.styleText('client_models_channel_selfkick', [options.kiwi.by], msg), 'action kick', {time: options.kiwi.time}); + this.addMsg(' ', styleText('client_models_channel_selfkick', {'%T': translateText('client_models_channel_selfkick', [options.kiwi.by, msg]), '%C': name}), 'action kick', {time: options.kiwi.time}); } } else if (show_message) { - this.addMsg(' ', _kiwi.global.text_theme.styleText('client_models_channel_part', [member.displayNick(true)], msg), 'action part', {time: options.kiwi.time}); + this.addMsg(' ', styleText('client_models_channel_part', {'%M': member.getMemberMask(), '%T': translateText('client_models_channel_part', [msg]), '%C': name}), 'action part', {time: options.kiwi.time}); } }, this); diff --git a/client/src/models/member.js b/client/src/models/member.js index 588108d..a472b24 100644 --- a/client/src/models/member.js +++ b/client/src/models/member.js @@ -105,6 +105,10 @@ _kiwi.model.Member = Backbone.Model.extend({ return display; }, + getMemberMask: function () { + // Why to use %N and %H is quite clear here. %J is because %I is already for italic and %U for underlines. Better ideas ? + return {'%N': this.get('nick'), '%J': this.get("ident"), '%H': this.get("hostname")}; + }, isOp: function () { var user_prefixes = _kiwi.gateway.get('user_prefixes'), modes = this.get('modes'), diff --git a/client/src/models/network.js b/client/src/models/network.js index bb36391..287361f 100644 --- a/client/src/models/network.js +++ b/client/src/models/network.js @@ -170,7 +170,7 @@ // If not a valid channel name, display a warning if (!that.isChannelName(channel_name)) { - that.panels.server.addMsg('', _kiwi.global.i18n.translate('client_models_network_channel_invalid_name').fetch(channel_name)); + that.panels.server.addMsg('', styleText('client_models_network_channel_invalid_name', {'%T': translateText('client_models_network_channel_invalid_name', []), '%C': channel_name})); _kiwi.app.message.text(_kiwi.global.i18n.translate('client_models_network_channel_invalid_name').fetch(channel_name), {timeout: 5000}); return; } @@ -235,7 +235,7 @@ function onDisconnect(event) { $.each(this.panels.models, function (index, panel) { - panel.addMsg('', _kiwi.global.i18n.translate('client_models_network_disconnected').fetch(), 'action quit'); + panel.addMsg('', styleText('client_models_network_disconnected', {'%T': translateText('client_models_network_disconnected', [])}), 'action quit'); }); } @@ -430,7 +430,7 @@ member = panel.get('members').getByNick(event.nick); if (member) { member.set('nick', event.newnick); - panel.addMsg('', _kiwi.global.text_theme.styleText('client_models_network_nickname_changed', [event.nick, event.newnick], 'action nick', {time: event.time})); + panel.addMsg('', styleText('client_models_network_nickname_changed', {'%M': member.getMemberMask(), '%T': translateText('client_models_network_nickname_changed', [event.newnick]), '%C': name}), 'action nick', {time: event.time}); } }); } @@ -553,7 +553,7 @@ if (!c) return; when = formatDate(new Date(event.when * 1000)); - c.addMsg('', _kiwi.global.i18n.translate('client_models_network_topic').fetch(event.nick, when), 'topic'); + c.addMsg('', styleText('client_models_network_topic', {'%T': translateText('client_models_network_topic', [event.nick, when]), '%C': event.channel}), 'topic'); } @@ -688,7 +688,8 @@ request_updated_banlist = true; } - channel.addMsg('', _kiwi.global.text_theme.styleText('client_models_network_mode', [event.nick, friendlyModeString()]), 'action mode', {time: event.time}); + console.log('event', event); + channel.addMsg('', styleText('client_models_network_mode', {'%N': event.nick, '%T': translateText('client_models_network_mode', [friendlyModeString()]), '%C': event.target}), 'action mode', {time: event.time}); // TODO: Be smart, remove the specific ban from the banlist rather than request a whole banlist if (request_updated_banlist) @@ -697,7 +698,7 @@ } else { // This is probably a mode being set on us. if (event.target.toLowerCase() === this.get("nick").toLowerCase()) { - this.panels.server.addMsg('', _kiwi.global.text_theme.styleText('client_models_network_selfmode', [event.nick, friendlyModeString()]), 'action mode'); + this.panels.server.addMsg('', styleText('client_models_network_selfmode', {'%N': event.nick, '%T': translateText('client_models_network_mode', [friendlyModeString()]), '%C': event.target}), 'action mode'); } else { console.log('MODE command recieved for unknown target %s: ', event.target, event); } @@ -721,9 +722,9 @@ if (event.ident) { panel.addMsg(event.nick, event.nick + ' [' + event.nick + '!' + event.ident + '@' + event.host + '] * ' + event.msg, 'whois'); } else if (event.chans) { - panel.addMsg(event.nick, _kiwi.global.i18n.translate('client_models_network_channels').fetch(event.chans), 'whois'); + panel.addMsg(event.nick, styleText('client_models_network_channels', {'%N': event.nick, '%T': translateText('client_models_network_channels', [event.chans])}), 'whois'); } else if (event.irc_server) { - panel.addMsg(event.nick, _kiwi.global.i18n.translate('client_models_network_server').fetch(event.irc_server, event.server_info), 'whois'); + panel.addMsg(event.nick, styleText('client_models_network_server', {'%N': event.nick, '%T': translateText('client_models_network_server', [event.irc_server, event.server_info])}), 'whois'); } else if (event.msg) { panel.addMsg(event.nick, event.msg, 'whois'); } else if (event.logon) { @@ -731,11 +732,11 @@ logon_date.setTime(event.logon * 1000); logon_date = formatDate(logon_date); - panel.addMsg(event.nick, _kiwi.global.i18n.translate('client_models_network_idle_and_signon').fetch(idle_time, logon_date), 'whois'); + panel.addMsg(event.nick, styleText('client_models_network_idle_and_signon', {'%N': event.nick, '%T': translateText('client_models_network_idle_and_signon', [idle_time, logon_date])}), 'whois'); } else if (event.away_reason) { - panel.addMsg(event.nick, _kiwi.global.i18n.translate('client_models_network_away').fetch(event.away_reason), 'whois'); + panel.addMsg(event.nick, styleText('client_models_network_away', {'%N': event.nick, '%T': translateText('client_models_network_away', [event.away_reason])}), 'whois'); } else { - panel.addMsg(event.nick, _kiwi.global.i18n.translate('client_models_network_idle').fetch(idle_time), 'whois'); + panel.addMsg(event.nick, client_models_network_server('client_models_network_idle', {'%N': event.nick, '%T': translateText('client_models_network_idle', [idle_time])}), 'whois'); } } @@ -749,7 +750,7 @@ if (event.host) { panel.addMsg(event.nick, event.nick + ' [' + event.nick + ((event.ident)? '!' + event.ident : '') + '@' + event.host + '] * ' + event.real_name, 'whois'); } else { - panel.addMsg(event.nick, _kiwi.global.i18n.translate('client_models_network_nickname_notfound').fetch(), 'whois'); + panel.addMsg(event.nick, styleText('client_models_network_nickname_notfound', {'%N': event.nick, '%T': translateText('client_models_network_nickname_notfound', [])}), 'whois'); } } @@ -783,22 +784,22 @@ switch (event.error) { case 'banned_from_channel': - panel.addMsg(' ', _kiwi.global.text_theme.styleText('client_models_network_banned', [event.channel, event.reason]), 'status'); + panel.addMsg(' ', styleText('client_models_network_banned', {'%N': event.nick, '%T': translateText('client_models_network_banned', [event.channel, event.reason]), '%C': event.channel}), 'status'); _kiwi.app.message.text(_kiwi.global.i18n.translate('client_models_network_banned').fetch(event.channel, event.reason)); break; case 'bad_channel_key': - panel.addMsg(' ', _kiwi.global.text_theme.styleText('client_models_network_channel_badkey', [event.channel]), 'status'); + panel.addMsg(' ', styleText('client_models_network_channel_badkey', {'%N': event.nick, '%T': translateText('client_models_network_channel_badkey', [event.channel]), '%C': event.channel}), 'status'); _kiwi.app.message.text(_kiwi.global.i18n.translate('client_models_network_channel_badkey').fetch(event.channel)); break; case 'invite_only_channel': - panel.addMsg(' ', _kiwi.global.text_theme.styleText('client_models_network_channel_inviteonly', [event.channel]), 'status'); + panel.addMsg(' ', styleText('client_models_network_channel_inviteonly', {'%N': event.nick, '%T': translateText('client_models_network_channel_inviteonly', [event.channel]), '%C': event.channel}), 'status'); _kiwi.app.message.text(_kiwi.global.i18n.translate('client_models_network_channel_inviteonly').fetch(event.channel)); break; case 'user_on_channel': panel.addMsg(' ', '== ' + event.nick + ' is already on this channel'); break; case 'channel_is_full': - panel.addMsg(' ', _kiwi.global.text_theme.styleText('client_models_network_channel_limitreached', [event.channel]), 'status'); + panel.addMsg(' ', styleText('client_models_network_channel_limitreached', {'%N': event.nick, '%T': translateText('client_models_network_channel_limitreached', [event.channel]), '%C': event.channel}), 'status'); _kiwi.app.message.text(_kiwi.global.i18n.translate('client_models_network_channel_limitreached').fetch(event.channel)); break; case 'chanop_privs_needed': @@ -814,7 +815,7 @@ } break; case 'nickname_in_use': - this.panels.server.addMsg(' ', _kiwi.global.text_theme.styleText('client_models_network_nickname_alreadyinuse', [event.nick]), 'status'); + this.panels.server.addMsg(' ', styleText('client_models_network_nickname_alreadyinuse', {'%N': event.nick, '%T': translateText('client_models_network_nickname_alreadyinuse', [event.nick]), '%C': event.channel}), 'status'); if (this.panels.server !== this.panels.active) { _kiwi.app.message.text(_kiwi.global.i18n.translate('client_models_network_nickname_alreadyinuse').fetch(event.nick)); } @@ -827,7 +828,7 @@ break; case 'password_mismatch': - this.panels.server.addMsg(' ', _kiwi.global.text_theme.styleText('client_models_network_badpassword'), 'status'); + this.panels.server.addMsg(' ', styleText('client_models_network_badpassword', {'%N': event.nick, '%T': translateText('client_models_network_badpassword', []), '%C': event.channel}), 'status'); break; default: // We don't know what data contains, so don't do anything with it. diff --git a/client/src/translations/en-gb.po b/client/src/translations/en-gb.po index 5f40c20..91ba4e4 100755 --- a/client/src/translations/en-gb.po +++ b/client/src/translations/en-gb.po @@ -178,15 +178,15 @@ msgstr "Error connecting to %s:%s (%s)" #: client/assets/src/models/channel.js msgid "client_models_channel_join" -msgstr "%s has joined" +msgstr "has joined" #: msgid "client_models_channel_quit" -msgstr "%s has quit %s" +msgstr "has quit %s" #: msgid "client_models_channel_kicked" -msgstr "%s was kicked by %s %s" +msgstr "was kicked by %s %s" #: msgid "client_models_channel_selfkick" @@ -194,11 +194,11 @@ msgstr "You have been kicked by %s %s" #: msgid "client_models_channel_part" -msgstr "%s has left %s" +msgstr "has left %s" #: client/assets/src/models/network.js msgid "client_models_network_channel_invalid_name" -msgstr "%s is not a valid channel name" +msgstr "is not a valid channel name" #: msgid "client_models_network_disconnected" @@ -206,7 +206,7 @@ msgstr "Disconnected from the IRC network" #: msgid "client_models_network_nickname_changed" -msgstr "%s is now known as %s" +msgstr "is now known as %s" #: msgid "client_models_network_topic" @@ -214,11 +214,11 @@ msgstr "Topic set by %s at %s" #: msgid "client_models_network_selfmode" -msgstr "%s sets mode %s" +msgstr "sets mode %s" #: msgid "client_models_network_mode" -msgstr "%s set mode %s" +msgstr "set mode %s" #: msgid "client_models_network_channels" @@ -254,11 +254,11 @@ msgstr "Bad channel key for %s" #: msgid "client_models_network_channel_inviteonly" -msgstr "%s is invite only." +msgstr "is invite only." #: msgid "client_models_network_channel_limitreached" -msgstr "%s is full." +msgstr "is full." #: msgid "client_models_network_nickname_alreadyinuse" diff --git a/client/src/translations/fr.po b/client/src/translations/fr.po index 4e74a0a..d37c3fb 100644 --- a/client/src/translations/fr.po +++ b/client/src/translations/fr.po @@ -178,15 +178,15 @@ msgstr "Erreur de connexion à %s:%s (%s)." #: client/assets/src/models/channel.js msgid "client_models_channel_join" -msgstr "%s a rejoint" +msgstr "a rejoint" #: msgid "client_models_channel_quit" -msgstr "%s a quitté %s" +msgstr "a quitté %s" #: msgid "client_models_channel_kicked" -msgstr "%s a été expulsé par %s : %s" +msgstr "a été expulsé par %s : %s" #: msgid "client_models_channel_selfkick" @@ -194,11 +194,11 @@ msgstr "Vous avez été expulsé par %s : %s." #: msgid "client_models_channel_part" -msgstr "%s est parti du canal %s" +msgstr "est parti du canal %s" #: client/assets/src/models/network.js msgid "client_models_network_channel_invalid_name" -msgstr "%s n'est pas un nom de canal valide." +msgstr "n'est pas un nom de canal valide." #: msgid "client_models_network_disconnected" @@ -206,7 +206,7 @@ msgstr "Déconnecté du réseau IRC." #: msgid "client_models_network_nickname_changed" -msgstr "%s est désormais connu comme %s" +msgstr "est désormais connu comme %s" #: msgid "client_models_network_topic" @@ -214,11 +214,11 @@ msgstr "Sujet défini par %s le %s" #: msgid "client_models_network_selfmode" -msgstr "%s a modifié les modes : %s" +msgstr "a modifié les modes : %s" #: msgid "client_models_network_mode" -msgstr "%s a modifié les modes : %s" +msgstr "a modifié les modes : %s" #: msgid "client_models_network_channels" @@ -254,11 +254,11 @@ msgstr "Mauvaise clef pour le canal %s." #: msgid "client_models_network_channel_inviteonly" -msgstr "%s est sur invitation uniquement." +msgstr "est sur invitation uniquement." #: msgid "client_models_network_channel_limitreached" -msgstr "%s est rempli." +msgstr "est rempli." #: msgid "client_models_network_nickname_alreadyinuse" diff --git a/client/src/views/channel.js b/client/src/views/channel.js index 7250b36..4af9873 100644 --- a/client/src/views/channel.js +++ b/client/src/views/channel.js @@ -228,7 +228,7 @@ _kiwi.view.Channel = _kiwi.view.Panel.extend({ topic = this.model.get("topic"); } - this.model.addMsg('', _kiwi.global.text_theme.styleText('client_views_channel_topic', [this.model.get('name'), topic]), 'topic'); + this.model.addMsg('', styleText('client_views_channel_topic', {'%T': translateText('client_views_channel_topic', [this.model.get('name'), topic]), '%C': this.model.get('name')}), 'topic'); // If this is the active channel then update the topic bar if (_kiwi.app.panels().active === this) { diff --git a/client/src/views/texttheme.js b/client/src/views/texttheme.js index 0250ccb..68450a4 100644 --- a/client/src/views/texttheme.js +++ b/client/src/views/texttheme.js @@ -2,19 +2,24 @@ _kiwi.view.TextTheme = _kiwi.view.Panel.extend({ initialize: function(text_theme) { this.text_theme = text_theme; }, - getText: function(string_id, params, trailing = '') { - var translation; - - translation = _kiwi.global.i18n.translate(string_id).fetch(params); - - return translation + trailing; - }, - styleText: function(string_id, params, trailing = '') { + styleText: function(string_id, params) { var style, text; style = formatToIrcMsg(_kiwi.global.text_theme.options[string_id]); - text = this.getText(string_id, params, trailing); - return style.replace('%T', text); + // Bring member info back to first level of params + if (params['%M']) { + for(key in params['%M']) { + params[key] = params['%M'][key]; + } + } + + text = style.replace(/%([TJHNC])/g, function(match, key) { + key = '%' + key; + + if (typeof params[key.toUpperCase()] !== 'undefined') + return params[key.toUpperCase()]; + }); + return text; } }); \ No newline at end of file -- 2.25.1