From 67d5ba8ebd34098662342c6f2c14b02f083d6306 Mon Sep 17 00:00:00 2001 From: "silver%warwickcompsoc.co.uk" Date: Thu, 3 Nov 2005 18:31:37 +0000 Subject: [PATCH] Bug 313802 - Make ChatZilla complain to the user if Mozilla/Firefox has selected a bad locale, so they stand a chance of fixing it. ChatZilla only. r=samuel --- extensions/irc/js/lib/utils.js | 22 +++++++++++ extensions/irc/xul/content/messages.js | 29 +++++++++++++++ extensions/irc/xul/content/static.js | 1 + .../irc/xul/locale/en-US/chatzilla.properties | 37 +++++++++++++++++++ 4 files changed, 89 insertions(+) diff --git a/extensions/irc/js/lib/utils.js b/extensions/irc/js/lib/utils.js index e914efd81b0..d2e88a60d39 100644 --- a/extensions/irc/js/lib/utils.js +++ b/extensions/irc/js/lib/utils.js @@ -1166,3 +1166,25 @@ function getSISpeed(speed) return getMsg(MSG_SI_SPEED, [data[1], getMsg("msg.si.speed." + data[0])]); } +// Returns -1 if version 1 is newer, +1 if version 2 is newer, and 0 for same. +function compareVersions(ver1, ver2) +{ + var ver1parts = ver1.split("."); + var ver2parts = ver2.split("."); + + while ((ver1parts.length > 0) && (ver2parts.length > 0)) + { + if (ver1parts[0] < ver2parts[0]) + return 1; + if (ver1parts[0] > ver2parts[0]) + return -1; + ver1parts.shift(); + ver2parts.shift(); + } + if (ver1parts.length > 0) + return -1; + if (ver2parts.length > 0) + return 1; + return 0; +} + diff --git a/extensions/irc/xul/content/messages.js b/extensions/irc/xul/content/messages.js index 0fb4905f59c..09754aad0a5 100644 --- a/extensions/irc/xul/content/messages.js +++ b/extensions/irc/xul/content/messages.js @@ -45,6 +45,35 @@ function initMessages() client.messageManager.loadBrands(); client.defaultBundle = client.messageManager.addBundle(path); + // Check we have a compatible locale version! + var localeVer = getMsg("locale.version"); + // We only care if the required version is newer than the selected (== -1). + if (compareVersions(__cz_locale, localeVer) < 0) + { + var selectedLocale = MSG_UNKNOWN; + try + { + var chromeReg = getService("@mozilla.org/chrome/chrome-registry;1", + "nsIXULChromeRegistry"); + selectedLocale = chromeReg.getSelectedLocale("chatzilla"); + } + catch (ex) {} + var msg = getMsg("locale.error", [__cz_version, __cz_locale, + selectedLocale, localeVer]); + if (msg == "locale.error") + { + // Yes, this is not localized - but that's only for when we don't + // *have* the localized string! + msg = "ChatZilla " + __cz_version + " locale mismatch!\n\n" + + "Expected locale version " + __cz_locale + + ", but currently selected locale (" + selectedLocale + + ") is version " + localeVer + "."; + } + if (typeof MSG_ALERT == "undefined") + MSG_ALERT = "Alert"; + alert(msg); + } + client.viewName = client.unicodeName = MSG_CLIENT_NAME; client.responseCodeMap = { diff --git a/extensions/irc/xul/content/static.js b/extensions/irc/xul/content/static.js index aca736ff92d..f4c482b420c 100644 --- a/extensions/irc/xul/content/static.js +++ b/extensions/irc/xul/content/static.js @@ -43,6 +43,7 @@ const __cz_version = "0.9.67+"; const __cz_condition = "green"; const __cz_suffix = ""; const __cz_guid = "59c81df5-4b7a-477b-912d-4e0fdf64e5f2"; +const __cz_locale = "0.9.67.1"; var warn; var ASSERT; diff --git a/extensions/irc/xul/locale/en-US/chatzilla.properties b/extensions/irc/xul/locale/en-US/chatzilla.properties index 51bc1ec29c5..71cf381a6c5 100644 --- a/extensions/irc/xul/locale/en-US/chatzilla.properties +++ b/extensions/irc/xul/locale/en-US/chatzilla.properties @@ -37,6 +37,43 @@ # # ***** END LICENSE BLOCK ***** +### Notes for localizers ### +# +# The following version number is the "localisation version number", and MUST +# match the locale.version in the original locale this is based on. In other +# words, if the locale.version in two files is the same, both files MUST have +# exactly the same list of locale strings. +# +# If you always start with an en-US locale, and replace all strings, you can +# leave this value alone. If you update your locale file based on changes in +# the en-US locale, please remember to always update this in your locale to +# match en-US when you're done. +# +# locale.error is the message is the message displayed to the user if the +# locale version number does not match what ChatZilla is expecting, and will +# have the the following replacements: +# +# %1$S ChatZilla version (e.g. "0.9.69"). +# %2$S Expected locale version (e.g. "0.9.69"). +# %3$S Locale being loaded (e.g. "fr-FR"). +# %4$S Actual locale version being (e.g. "0.9.68.2"). +# +# In the example above, the user would be using ChatZilla 0.9.69, which +# expects a locale version of 0.9.69. It tried to use the fr-FR locale, +# but found it was only version 0.9.68.3. +# +# Note: the ChatZilla version and expected locale versions may not always be +# the same. For example, if only non-locale changes have been made, the +# expected locale version will stay the same. This is to make using +# localisations between versions easier. +# +### End of notes ### + +locale.version = 0.9.67.1 +locale.error = You are using ChatZilla %1$S, which requires the locale version %2$S. The currently selected locale, %3$S, is version %4$S, and therefore there may be problems running ChatZilla.\n\nIt is strongly advised that you update or remove the ChatZilla locale in question. + +# Misc + unknown= none= na=