From c8103154a9c961a32ca3ed8b6aae7caa6be8f397 Mon Sep 17 00:00:00 2001 From: Nick Winter Date: Thu, 13 Mar 2014 09:02:19 -0700 Subject: [PATCH] Using the new i18n utility function everywhere. Fixed big bug with spell palette i18n. --- app/lib/scripts/SpriteScriptModule.coffee | 8 ++++---- app/lib/utils.coffee | 1 - .../play/level/tome/spell_palette.jade | 2 +- app/views/play/level/goals_view.coffee | 3 ++- app/views/play/level/modal/docs_modal.coffee | 9 +++++---- .../play/level/modal/victory_modal.coffee | 7 +++---- .../play/level/tome/spell_palette_view.coffee | 2 ++ app/views/play/level_view.coffee | 11 ++++++----- app/views/play/spectate_view.coffee | 18 +++++++++--------- 9 files changed, 32 insertions(+), 29 deletions(-) diff --git a/app/lib/scripts/SpriteScriptModule.coffee b/app/lib/scripts/SpriteScriptModule.coffee index d40ce2356..84585e0f3 100644 --- a/app/lib/scripts/SpriteScriptModule.coffee +++ b/app/lib/scripts/SpriteScriptModule.coffee @@ -1,6 +1,6 @@ ScriptModule = require './ScriptModule' {me} = require 'lib/auth' -util = require 'lib/utils' +utils = require 'lib/utils' module.exports = class SpritesScriptModule extends ScriptModule @neededFor: (noteGroup) -> @@ -36,9 +36,9 @@ module.exports = class SpritesScriptModule extends ScriptModule responses = sprite.say.responses responses = [] unless script.skippable or responses for response in responses ? [] - response.text = response.i18n?[me.lang()]?.text ? response.text - text = util.i18n(sprite.say, 'text') - blurb = util.i18n(sprite.say, 'blurb') + response.text = utils.i18n response, 'text' + text = utils.i18n sprite.say, 'text' + blurb = utils.i18n sprite.say, 'blurb' sound = sprite.say.sound # TODO support sound i18n note = channel: 'level-sprite-dialogue' diff --git a/app/lib/utils.coffee b/app/lib/utils.coffee index 278873eba..9b44dd320 100644 --- a/app/lib/utils.coffee +++ b/app/lib/utils.coffee @@ -66,5 +66,4 @@ module.exports.i18n = (say, target, language=me.lang(), fallback='en') -> return fallforwardResult if fallforwardResult? return fallbackResult if fallbackResult? return say[target] if target of say - return say.text if 'text' of say null diff --git a/app/templates/play/level/tome/spell_palette.jade b/app/templates/play/level/tome/spell_palette.jade index 19489b42c..d587da8c5 100644 --- a/app/templates/play/level/tome/spell_palette.jade +++ b/app/templates/play/level/tome/spell_palette.jade @@ -6,5 +6,5 @@ ul(class="nav nav-pills" + (tabbed ? ' multiple-tabs' : '')) h4= group .tab-content each slug, group in entryGroupSlugs - div(id="palette-tab-" + slug, class="tab-pane" + (group == "this" || slug == "available-spells" ? " active" : "")) + div(id="palette-tab-" + slug, class="tab-pane" + (group == "this" || slug == defaultGroupSlug ? " active" : "")) div(class="properties properties-" + slug) diff --git a/app/views/play/level/goals_view.coffee b/app/views/play/level/goals_view.coffee index b9eb3f89f..85d7436ac 100644 --- a/app/views/play/level/goals_view.coffee +++ b/app/views/play/level/goals_view.coffee @@ -1,6 +1,7 @@ View = require 'views/kinds/CocoView' template = require 'templates/play/level/goals' {me} = require 'lib/auth' +utils = require 'lib/utils' stateIconMap = incomplete: 'icon-minus' @@ -31,7 +32,7 @@ module.exports = class GoalsView extends View state = e.goalStates[goal.id] continue if goal.hiddenGoal and state.status isnt 'failure' continue if goal.team and me.team isnt goal.team - text = goal.i18n?[me.lang()]?.name ? goal.name + text = utils.i18n goal, 'name' if state.killed dead = _.filter(_.values(state.killed)).length targeted = _.values(state.killed).length diff --git a/app/views/play/level/modal/docs_modal.coffee b/app/views/play/level/modal/docs_modal.coffee index 3e9ab5cf8..42aa98319 100644 --- a/app/views/play/level/modal/docs_modal.coffee +++ b/app/views/play/level/modal/docs_modal.coffee @@ -1,13 +1,14 @@ View = require 'views/kinds/ModalView' template = require 'templates/play/level/modal/docs' Article = require 'models/Article' +utils = require 'lib/utils' # let's implement this once we have the docs database schema set up module.exports = class DocsModal extends View template: template id: 'docs-modal' - + shortcuts: 'enter': 'hide' @@ -25,8 +26,8 @@ module.exports = class DocsModal extends View @docs = specific.concat(general) marked.setOptions {gfm: true, sanitize: false, smartLists: true, breaks: false} @docs = _.cloneDeep(@docs) - doc.html = marked(doc.i18n?[me.lang()]?.body or doc.body) for doc in @docs - doc.name = (doc.i18n?[me.lang()]?.name or doc.name) for doc in @docs + doc.html = marked(utils.i18n doc, 'body') for doc in @docs + doc.name = (utils.i18n doc, 'name') for doc in @docs doc.slug = _.string.slugify(doc.name) for doc in @docs super() @@ -49,4 +50,4 @@ module.exports = class DocsModal extends View @$el.find('li.active').removeClass('active') onHidden: -> - Backbone.Mediator.publish 'level:docs-hidden' \ No newline at end of file + Backbone.Mediator.publish 'level:docs-hidden' diff --git a/app/views/play/level/modal/victory_modal.coffee b/app/views/play/level/modal/victory_modal.coffee index b339962c7..adf75f0d6 100644 --- a/app/views/play/level/modal/victory_modal.coffee +++ b/app/views/play/level/modal/victory_modal.coffee @@ -2,8 +2,7 @@ View = require 'views/kinds/ModalView' template = require 'templates/play/level/modal/victory' {me} = require 'lib/auth' LevelFeedback = require 'models/LevelFeedback' - -# let's implement this once we have the docs database schema set up +utils = require 'lib/utils' module.exports = class VictoryModal extends View id: 'level-victory-modal' @@ -26,7 +25,7 @@ module.exports = class VictoryModal extends View constructor: (options) -> victory = options.level.get('victory') - body = victory?.i18n?[me.lang()]?.body or victory.body or 'Sorry, this level has no victory message yet.' + body = utils.i18n(victory, 'body') or 'Sorry, this level has no victory message yet.' @body = marked(body) @level = options.level @session = options.session @@ -80,7 +79,7 @@ module.exports = class VictoryModal extends View c.body = @body c.me = me c.hasNextLevel = _.isObject(@level.get('nextLevel')) and (@level.get('name') isnt "Mobile Artillery") - c.levelName = @level.get('i18n')?[me.lang()]?.name ? @level.get('name') + c.levelName = utils.i18n @level.attributes, 'name' c.level = @level if c.level.get('type') is 'ladder' c1 = @session?.get('code') diff --git a/app/views/play/level/tome/spell_palette_view.coffee b/app/views/play/level/tome/spell_palette_view.coffee index 2ba25e5ed..3a1056733 100644 --- a/app/views/play/level/tome/spell_palette_view.coffee +++ b/app/views/play/level/tome/spell_palette_view.coffee @@ -27,6 +27,7 @@ module.exports = class SpellPaletteView extends View c.entryGroups = @entryGroups c.entryGroupSlugs = @entryGroupSlugs c.tabbed = _.size(@entryGroups) > 1 + c.defaultGroupSlug = @defaultGroupSlug c afterRender: -> @@ -89,6 +90,7 @@ module.exports = class SpellPaletteView extends View defaultGroup = $.i18n.t("play_level.tome_available_spells", defaultValue: "Available Spells") @entryGroups = {} @entryGroups[defaultGroup] = @entries + @defaultGroupSlug = _.string.slugify defaultGroup @entryGroupSlugs = {} for group, entries of @entryGroups @entryGroupSlugs[group] = _.string.slugify group diff --git a/app/views/play/level_view.coffee b/app/views/play/level_view.coffee index 1282297ba..8bd77c4ba 100644 --- a/app/views/play/level_view.coffee +++ b/app/views/play/level_view.coffee @@ -2,6 +2,7 @@ View = require 'views/kinds/RootView' template = require 'templates/play/level' {me} = require('lib/auth') ThangType = require 'models/ThangType' +utils = require 'lib/utils' # temp hard coded data World = require 'lib/world/world' @@ -153,7 +154,7 @@ module.exports = class PlayLevelView extends View if window.currentModal and not window.currentModal.destroyed @loadingScreen.showReady() return Backbone.Mediator.subscribeOnce 'modal-closed', @onLevelLoaderLoaded, @ - + localStorage["lastLevel"] = @levelID if localStorage? @grabLevelLoaderData() team = @getQueryVariable("team") ? @world.teamForPlayer(0) @@ -175,7 +176,7 @@ module.exports = class PlayLevelView extends View if @otherSession # TODO: colorize name and cloud by team, colorize wizard by user's color config @surface.createOpponentWizard id: @otherSession.get('creator'), name: @otherSession.get('creatorName'), team: @otherSession.get('team') - + grabLevelLoaderData: -> @session = @levelLoader.session @world = @levelLoader.world @@ -183,7 +184,7 @@ module.exports = class PlayLevelView extends View @otherSession = @levelLoader.opponentSession @levelLoader.destroy() @levelLoader = null - + loadOpponentTeam: (myTeam) -> opponentSpells = [] for spellTeam, spells of @session.get('teamSpells') ? @otherSession?.get('teamSpells') ? {} @@ -202,7 +203,7 @@ module.exports = class PlayLevelView extends View # For now, ladderGame will disallow multiplayer, because session code combining doesn't play nice yet. @session.set 'multiplayer', false - + onSupermodelLoadedOne: => @modelsLoaded ?= 0 @modelsLoaded += 1 @@ -224,7 +225,7 @@ module.exports = class PlayLevelView extends View @insertSubView new GoldView {} @insertSubView new HUDView {} @insertSubView new ChatView levelID: @levelID, sessionID: @session.id, session: @session - worldName = @level.get('i18n')?[me.lang()]?.name ? @level.get('name') + worldName = utils.i18n @level.attributes, 'name' @controlBar = @insertSubView new ControlBarView {worldName: worldName, session: @session, level: @level, supermodel: @supermodel, playableTeams: @world.playableTeams, ladderGame: subviewOptions.ladderGame} #Backbone.Mediator.publish('level-set-debug', debug: true) if me.displayName() is 'Nick!' diff --git a/app/views/play/spectate_view.coffee b/app/views/play/spectate_view.coffee index 00a6803b6..27cfcb1f4 100644 --- a/app/views/play/spectate_view.coffee +++ b/app/views/play/spectate_view.coffee @@ -2,8 +2,8 @@ View = require 'views/kinds/RootView' template = require 'templates/play/spectate' {me} = require('lib/auth') ThangType = require 'models/ThangType' +utils = require 'lib/utils' -# temp hard coded data World = require 'lib/world/world' # tools @@ -87,8 +87,8 @@ module.exports = class SpectateLevelView extends View @load() load: -> - @levelLoader = new LevelLoader - supermodel: @supermodel + @levelLoader = new LevelLoader + supermodel: @supermodel levelID: @levelID sessionID: @sessionOne opponentSessionID: @sessionTwo @@ -154,17 +154,17 @@ module.exports = class SpectateLevelView extends View @register() @controlBar.setBus(@bus) @surface.showLevel() - if me.id isnt @session.get 'creator' + if me.id isnt @session.get 'creator' @surface.createOpponentWizard id: @session.get('creator') name: @session.get('creatorName') team: @session.get('team') - - @surface.createOpponentWizard + + @surface.createOpponentWizard id: @otherSession.get('creator') name: @otherSession.get('creatorName') team: @otherSession.get('team') - + grabLevelLoaderData: -> @session = @levelLoader.session @@ -213,7 +213,7 @@ module.exports = class SpectateLevelView extends View @insertSubView new GoldView {} @insertSubView new HUDView {} - worldName = @level.get('i18n')?[me.lang()]?.name ? @level.get('name') + worldName = utils.i18n @level.attributes, 'name' @controlBar = @insertSubView new ControlBarView {worldName: worldName, session: @session, level: @level, supermodel: @supermodel, playableTeams: @world.playableTeams, spectateGame: true} #Backbone.Mediator.publish('level-set-debug', debug: true) if me.displayName() is 'Nick!' @@ -423,7 +423,7 @@ module.exports = class SpectateLevelView extends View continue unless thangType = _.find thangTypes, (m) -> m.get('name') is spriteName continue unless sound = AudioPlayer.soundForDialogue message, thangType.get('soundTriggers') AudioPlayer.preloadSoundReference sound - + onNextGamePressed: (e) -> console.log "You want to see the next game!" @sessionOne = "53193c8f7a89df21c4d968e9"