From 968c8998364f9b7ea8299e48130293412ad03ef8 Mon Sep 17 00:00:00 2001 From: Matteo Pagliazzi Date: Wed, 5 Mar 2014 17:04:22 +0100 Subject: [PATCH] improve(i18n): add locales for content.json, add code for server to i18n, build --- dist/habitrpg-shared.js | 74 +++++++++++++++++++++++++++++++---------- locales/de/content.json | 20 +++++++++++ locales/es/content.json | 20 +++++++++++ locales/fr/content.json | 20 +++++++++++ locales/it/content.json | 20 +++++++++++ locales/pl/content.json | 20 +++++++++++ locales/pt/content.json | 20 +++++++++++ locales/ru/content.json | 20 +++++++++++ locales/sk/content.json | 20 +++++++++++ locales/sv/content.json | 20 +++++++++++ locales/uk/content.json | 20 +++++++++++ script/i18n.coffee | 19 ++++++++--- 12 files changed, 271 insertions(+), 22 deletions(-) create mode 100644 locales/de/content.json create mode 100644 locales/es/content.json create mode 100644 locales/fr/content.json create mode 100644 locales/it/content.json create mode 100644 locales/pl/content.json create mode 100644 locales/pt/content.json create mode 100644 locales/ru/content.json create mode 100644 locales/sk/content.json create mode 100644 locales/sv/content.json create mode 100644 locales/uk/content.json diff --git a/dist/habitrpg-shared.js b/dist/habitrpg-shared.js index eb41cd4eae..9904c98938 100644 --- a/dist/habitrpg-shared.js +++ b/dist/habitrpg-shared.js @@ -10171,44 +10171,72 @@ gear = { }, rogue: { 0: { - text: "Dagger", - notes: 'A rogue\'s most basic weapon. Confers no benefit.', + text: (function() { + return i18n.t('weaponRogue0Text'); + }), + notes: (function() { + return i18n.t('weaponRogue0Notes'); + }), str: 0, value: 0 }, 1: { - text: "Short Sword", - notes: 'Light, concealable blade. Increases STR by 2.', + text: (function() { + return i18n.t('weaponRogue1Text'); + }), + notes: (function() { + return i18n.t('weaponRogue1Notes'); + }), str: 2, value: 20 }, 2: { - text: "Scimitar", - notes: 'Slashing sword, swift to deliver a killing blow. Increases STR by 3.', + text: (function() { + return i18n.t('weaponRogue2Text'); + }), + notes: (function() { + return i18n.t('weaponRogue2Notes'); + }), str: 3, value: 35 }, 3: { - text: "Kukri", - notes: 'Distinctive bush knife, both survival tool and weapon. Increases STR by 4.', + text: (function() { + return i18n.t('weaponRogue3Text'); + }), + notes: (function() { + return i18n.t('weaponRogue3Notes'); + }), str: 4, value: 50 }, 4: { - text: "Nunchaku", - notes: 'Heavy batons whirled about on a length of chain. Increases STR by 6.', + text: (function() { + return i18n.t('weaponRogue4Text'); + }), + notes: (function() { + return i18n.t('weaponRogue4Notes'); + }), str: 6, value: 70 }, 5: { - text: "Ninja-to", - notes: 'Sleek and deadly as the ninja themselves. Increases STR by 8.', + text: (function() { + return i18n.t('weaponRogue5Text'); + }), + notes: (function() { + return i18n.t('weaponRogue5Notes'); + }), str: 8, value: 90 }, 6: { - text: "Hook Sword", - notes: 'Complex weapon adept at ensnaring and disarming opponents. Increases STR by 10.', + text: (function() { + return i18n.t('weaponRogue6Text'); + }), + notes: (function() { + return i18n.t('weaponRogue6Notes'); + }), str: 10, value: 120, last: true @@ -11585,9 +11613,18 @@ _ = require('lodash'); module.exports = { strings: {}, - t: function(stringName, vars) { - var string; - string = module.exports.strings[stringName]; + translations: {}, + t: function(stringName) { + var locale, string, stringNotFound, vars; + vars = arguments[1]; + if (_.isString(arguments[1])) { + vars = null; + locale = arguments[1]; + } else if (arguments[2] != null) { + vars = arguments[1]; + locale = arguments[2]; + } + string = locale ? module.exports.translations[locale][stringName] : module.exports.strings[stringName]; if (string) { if (vars) { return _.template(string, vars); @@ -11595,7 +11632,8 @@ module.exports = { return string; } } else { - return _.template(module.exports.strings.stringNotFound, { + stringNotFound = locale ? module.exports.translations[locale].stringNotFound : module.exports.strings.stringNotFound; + return _.template(stringNotFound, { string: stringName }); } diff --git a/locales/de/content.json b/locales/de/content.json new file mode 100644 index 0000000000..3643c7a918 --- /dev/null +++ b/locales/de/content.json @@ -0,0 +1,20 @@ +{ + "weaponBase0Text": "No Weapon", + "weaponBase0Notes": "No Weapon.", + "weaponWarrior0Text": "Training Sword", + "weaponWarrior0Notes": "Practice weapon. Confers no benefit.", + "weaponWarrior1Text": "Sword", + "weaponWarrior1Notes": "Common soldier's blade. Increases STR by 3.", + "weaponWarrior2Text": "Axe", + "weaponWarrior2Notes": "Double-bitted battle-axe. Increases STR by 6", + "weaponWarrior3Text": "Morning Star", + "weaponWarrior3Notes": "Heavy club with brutal spikes. Increases STR by 9.", + "weaponWarrior4Text": "Sapphire Blade", + "weaponWarrior4Notes": "Sword whose edge bites like the north wind. Increases STR by 12.", + "weaponWarrior5Text": "Ruby Sword", + "weaponWarrior5Notes": "Weapon whose forge-glow never fades. Increases STR by 15.", + "weaponWarrior6Text": "Golden Sword", + "weaponWarrior6Notes": "Bane of creatures of darkness. Increases STR by 18.", + "weaponRogue0Text": "Hook Sword", + "weaponRogue0Notes": "Complex weapon adept at ensnaring and disarming opponents. Increases STR by 10." +} \ No newline at end of file diff --git a/locales/es/content.json b/locales/es/content.json new file mode 100644 index 0000000000..3643c7a918 --- /dev/null +++ b/locales/es/content.json @@ -0,0 +1,20 @@ +{ + "weaponBase0Text": "No Weapon", + "weaponBase0Notes": "No Weapon.", + "weaponWarrior0Text": "Training Sword", + "weaponWarrior0Notes": "Practice weapon. Confers no benefit.", + "weaponWarrior1Text": "Sword", + "weaponWarrior1Notes": "Common soldier's blade. Increases STR by 3.", + "weaponWarrior2Text": "Axe", + "weaponWarrior2Notes": "Double-bitted battle-axe. Increases STR by 6", + "weaponWarrior3Text": "Morning Star", + "weaponWarrior3Notes": "Heavy club with brutal spikes. Increases STR by 9.", + "weaponWarrior4Text": "Sapphire Blade", + "weaponWarrior4Notes": "Sword whose edge bites like the north wind. Increases STR by 12.", + "weaponWarrior5Text": "Ruby Sword", + "weaponWarrior5Notes": "Weapon whose forge-glow never fades. Increases STR by 15.", + "weaponWarrior6Text": "Golden Sword", + "weaponWarrior6Notes": "Bane of creatures of darkness. Increases STR by 18.", + "weaponRogue0Text": "Hook Sword", + "weaponRogue0Notes": "Complex weapon adept at ensnaring and disarming opponents. Increases STR by 10." +} \ No newline at end of file diff --git a/locales/fr/content.json b/locales/fr/content.json new file mode 100644 index 0000000000..3643c7a918 --- /dev/null +++ b/locales/fr/content.json @@ -0,0 +1,20 @@ +{ + "weaponBase0Text": "No Weapon", + "weaponBase0Notes": "No Weapon.", + "weaponWarrior0Text": "Training Sword", + "weaponWarrior0Notes": "Practice weapon. Confers no benefit.", + "weaponWarrior1Text": "Sword", + "weaponWarrior1Notes": "Common soldier's blade. Increases STR by 3.", + "weaponWarrior2Text": "Axe", + "weaponWarrior2Notes": "Double-bitted battle-axe. Increases STR by 6", + "weaponWarrior3Text": "Morning Star", + "weaponWarrior3Notes": "Heavy club with brutal spikes. Increases STR by 9.", + "weaponWarrior4Text": "Sapphire Blade", + "weaponWarrior4Notes": "Sword whose edge bites like the north wind. Increases STR by 12.", + "weaponWarrior5Text": "Ruby Sword", + "weaponWarrior5Notes": "Weapon whose forge-glow never fades. Increases STR by 15.", + "weaponWarrior6Text": "Golden Sword", + "weaponWarrior6Notes": "Bane of creatures of darkness. Increases STR by 18.", + "weaponRogue0Text": "Hook Sword", + "weaponRogue0Notes": "Complex weapon adept at ensnaring and disarming opponents. Increases STR by 10." +} \ No newline at end of file diff --git a/locales/it/content.json b/locales/it/content.json new file mode 100644 index 0000000000..3643c7a918 --- /dev/null +++ b/locales/it/content.json @@ -0,0 +1,20 @@ +{ + "weaponBase0Text": "No Weapon", + "weaponBase0Notes": "No Weapon.", + "weaponWarrior0Text": "Training Sword", + "weaponWarrior0Notes": "Practice weapon. Confers no benefit.", + "weaponWarrior1Text": "Sword", + "weaponWarrior1Notes": "Common soldier's blade. Increases STR by 3.", + "weaponWarrior2Text": "Axe", + "weaponWarrior2Notes": "Double-bitted battle-axe. Increases STR by 6", + "weaponWarrior3Text": "Morning Star", + "weaponWarrior3Notes": "Heavy club with brutal spikes. Increases STR by 9.", + "weaponWarrior4Text": "Sapphire Blade", + "weaponWarrior4Notes": "Sword whose edge bites like the north wind. Increases STR by 12.", + "weaponWarrior5Text": "Ruby Sword", + "weaponWarrior5Notes": "Weapon whose forge-glow never fades. Increases STR by 15.", + "weaponWarrior6Text": "Golden Sword", + "weaponWarrior6Notes": "Bane of creatures of darkness. Increases STR by 18.", + "weaponRogue0Text": "Hook Sword", + "weaponRogue0Notes": "Complex weapon adept at ensnaring and disarming opponents. Increases STR by 10." +} \ No newline at end of file diff --git a/locales/pl/content.json b/locales/pl/content.json new file mode 100644 index 0000000000..3643c7a918 --- /dev/null +++ b/locales/pl/content.json @@ -0,0 +1,20 @@ +{ + "weaponBase0Text": "No Weapon", + "weaponBase0Notes": "No Weapon.", + "weaponWarrior0Text": "Training Sword", + "weaponWarrior0Notes": "Practice weapon. Confers no benefit.", + "weaponWarrior1Text": "Sword", + "weaponWarrior1Notes": "Common soldier's blade. Increases STR by 3.", + "weaponWarrior2Text": "Axe", + "weaponWarrior2Notes": "Double-bitted battle-axe. Increases STR by 6", + "weaponWarrior3Text": "Morning Star", + "weaponWarrior3Notes": "Heavy club with brutal spikes. Increases STR by 9.", + "weaponWarrior4Text": "Sapphire Blade", + "weaponWarrior4Notes": "Sword whose edge bites like the north wind. Increases STR by 12.", + "weaponWarrior5Text": "Ruby Sword", + "weaponWarrior5Notes": "Weapon whose forge-glow never fades. Increases STR by 15.", + "weaponWarrior6Text": "Golden Sword", + "weaponWarrior6Notes": "Bane of creatures of darkness. Increases STR by 18.", + "weaponRogue0Text": "Hook Sword", + "weaponRogue0Notes": "Complex weapon adept at ensnaring and disarming opponents. Increases STR by 10." +} \ No newline at end of file diff --git a/locales/pt/content.json b/locales/pt/content.json new file mode 100644 index 0000000000..3643c7a918 --- /dev/null +++ b/locales/pt/content.json @@ -0,0 +1,20 @@ +{ + "weaponBase0Text": "No Weapon", + "weaponBase0Notes": "No Weapon.", + "weaponWarrior0Text": "Training Sword", + "weaponWarrior0Notes": "Practice weapon. Confers no benefit.", + "weaponWarrior1Text": "Sword", + "weaponWarrior1Notes": "Common soldier's blade. Increases STR by 3.", + "weaponWarrior2Text": "Axe", + "weaponWarrior2Notes": "Double-bitted battle-axe. Increases STR by 6", + "weaponWarrior3Text": "Morning Star", + "weaponWarrior3Notes": "Heavy club with brutal spikes. Increases STR by 9.", + "weaponWarrior4Text": "Sapphire Blade", + "weaponWarrior4Notes": "Sword whose edge bites like the north wind. Increases STR by 12.", + "weaponWarrior5Text": "Ruby Sword", + "weaponWarrior5Notes": "Weapon whose forge-glow never fades. Increases STR by 15.", + "weaponWarrior6Text": "Golden Sword", + "weaponWarrior6Notes": "Bane of creatures of darkness. Increases STR by 18.", + "weaponRogue0Text": "Hook Sword", + "weaponRogue0Notes": "Complex weapon adept at ensnaring and disarming opponents. Increases STR by 10." +} \ No newline at end of file diff --git a/locales/ru/content.json b/locales/ru/content.json new file mode 100644 index 0000000000..3643c7a918 --- /dev/null +++ b/locales/ru/content.json @@ -0,0 +1,20 @@ +{ + "weaponBase0Text": "No Weapon", + "weaponBase0Notes": "No Weapon.", + "weaponWarrior0Text": "Training Sword", + "weaponWarrior0Notes": "Practice weapon. Confers no benefit.", + "weaponWarrior1Text": "Sword", + "weaponWarrior1Notes": "Common soldier's blade. Increases STR by 3.", + "weaponWarrior2Text": "Axe", + "weaponWarrior2Notes": "Double-bitted battle-axe. Increases STR by 6", + "weaponWarrior3Text": "Morning Star", + "weaponWarrior3Notes": "Heavy club with brutal spikes. Increases STR by 9.", + "weaponWarrior4Text": "Sapphire Blade", + "weaponWarrior4Notes": "Sword whose edge bites like the north wind. Increases STR by 12.", + "weaponWarrior5Text": "Ruby Sword", + "weaponWarrior5Notes": "Weapon whose forge-glow never fades. Increases STR by 15.", + "weaponWarrior6Text": "Golden Sword", + "weaponWarrior6Notes": "Bane of creatures of darkness. Increases STR by 18.", + "weaponRogue0Text": "Hook Sword", + "weaponRogue0Notes": "Complex weapon adept at ensnaring and disarming opponents. Increases STR by 10." +} \ No newline at end of file diff --git a/locales/sk/content.json b/locales/sk/content.json new file mode 100644 index 0000000000..3643c7a918 --- /dev/null +++ b/locales/sk/content.json @@ -0,0 +1,20 @@ +{ + "weaponBase0Text": "No Weapon", + "weaponBase0Notes": "No Weapon.", + "weaponWarrior0Text": "Training Sword", + "weaponWarrior0Notes": "Practice weapon. Confers no benefit.", + "weaponWarrior1Text": "Sword", + "weaponWarrior1Notes": "Common soldier's blade. Increases STR by 3.", + "weaponWarrior2Text": "Axe", + "weaponWarrior2Notes": "Double-bitted battle-axe. Increases STR by 6", + "weaponWarrior3Text": "Morning Star", + "weaponWarrior3Notes": "Heavy club with brutal spikes. Increases STR by 9.", + "weaponWarrior4Text": "Sapphire Blade", + "weaponWarrior4Notes": "Sword whose edge bites like the north wind. Increases STR by 12.", + "weaponWarrior5Text": "Ruby Sword", + "weaponWarrior5Notes": "Weapon whose forge-glow never fades. Increases STR by 15.", + "weaponWarrior6Text": "Golden Sword", + "weaponWarrior6Notes": "Bane of creatures of darkness. Increases STR by 18.", + "weaponRogue0Text": "Hook Sword", + "weaponRogue0Notes": "Complex weapon adept at ensnaring and disarming opponents. Increases STR by 10." +} \ No newline at end of file diff --git a/locales/sv/content.json b/locales/sv/content.json new file mode 100644 index 0000000000..3643c7a918 --- /dev/null +++ b/locales/sv/content.json @@ -0,0 +1,20 @@ +{ + "weaponBase0Text": "No Weapon", + "weaponBase0Notes": "No Weapon.", + "weaponWarrior0Text": "Training Sword", + "weaponWarrior0Notes": "Practice weapon. Confers no benefit.", + "weaponWarrior1Text": "Sword", + "weaponWarrior1Notes": "Common soldier's blade. Increases STR by 3.", + "weaponWarrior2Text": "Axe", + "weaponWarrior2Notes": "Double-bitted battle-axe. Increases STR by 6", + "weaponWarrior3Text": "Morning Star", + "weaponWarrior3Notes": "Heavy club with brutal spikes. Increases STR by 9.", + "weaponWarrior4Text": "Sapphire Blade", + "weaponWarrior4Notes": "Sword whose edge bites like the north wind. Increases STR by 12.", + "weaponWarrior5Text": "Ruby Sword", + "weaponWarrior5Notes": "Weapon whose forge-glow never fades. Increases STR by 15.", + "weaponWarrior6Text": "Golden Sword", + "weaponWarrior6Notes": "Bane of creatures of darkness. Increases STR by 18.", + "weaponRogue0Text": "Hook Sword", + "weaponRogue0Notes": "Complex weapon adept at ensnaring and disarming opponents. Increases STR by 10." +} \ No newline at end of file diff --git a/locales/uk/content.json b/locales/uk/content.json new file mode 100644 index 0000000000..3643c7a918 --- /dev/null +++ b/locales/uk/content.json @@ -0,0 +1,20 @@ +{ + "weaponBase0Text": "No Weapon", + "weaponBase0Notes": "No Weapon.", + "weaponWarrior0Text": "Training Sword", + "weaponWarrior0Notes": "Practice weapon. Confers no benefit.", + "weaponWarrior1Text": "Sword", + "weaponWarrior1Notes": "Common soldier's blade. Increases STR by 3.", + "weaponWarrior2Text": "Axe", + "weaponWarrior2Notes": "Double-bitted battle-axe. Increases STR by 6", + "weaponWarrior3Text": "Morning Star", + "weaponWarrior3Notes": "Heavy club with brutal spikes. Increases STR by 9.", + "weaponWarrior4Text": "Sapphire Blade", + "weaponWarrior4Notes": "Sword whose edge bites like the north wind. Increases STR by 12.", + "weaponWarrior5Text": "Ruby Sword", + "weaponWarrior5Notes": "Weapon whose forge-glow never fades. Increases STR by 15.", + "weaponWarrior6Text": "Golden Sword", + "weaponWarrior6Notes": "Bane of creatures of darkness. Increases STR by 18.", + "weaponRogue0Text": "Hook Sword", + "weaponRogue0Notes": "Complex weapon adept at ensnaring and disarming opponents. Increases STR by 10." +} \ No newline at end of file diff --git a/script/i18n.coffee b/script/i18n.coffee index a4d415ead3..f12f2454f0 100644 --- a/script/i18n.coffee +++ b/script/i18n.coffee @@ -1,11 +1,22 @@ _ = require 'lodash' module.exports = - strings: {} - t: (stringName, vars) -> - string = module.exports.strings[stringName] + strings: {}, # Strings for one single language + translations: {} # Strings for multiple languages {en: strings, de: strings, ...} + t: (stringName) -> # Other parameters allowed are vars (Object) and locale (String) + vars = arguments[1] + + if _.isString(arguments[1]) + vars = null + locale = arguments[1] + else if arguments[2]? + vars = arguments[1] + locale = arguments[2] + + string = if locale then module.exports.translations[locale][stringName] else module.exports.strings[stringName] if string if vars then _.template(string, vars) else string else - _.template(module.exports.strings.stringNotFound, {string: stringName}) \ No newline at end of file + stringNotFound = if locale then module.exports.translations[locale].stringNotFound else module.exports.strings.stringNotFound + _.template(stringNotFound, {string: stringName}) \ No newline at end of file