mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-05-02 17:03:42 -04:00
Added i18n support for level code comments.
This commit is contained in:
parent
c7713b4105
commit
5ba1f61abe
7 changed files with 44 additions and 11 deletions
app
|
@ -12,6 +12,7 @@ module.exports = class LevelComponent extends CocoModel
|
||||||
@LandID: '524b7aff7fc0f6d519000006'
|
@LandID: '524b7aff7fc0f6d519000006'
|
||||||
@CollidesID: '524b7b857fc0f6d519000012'
|
@CollidesID: '524b7b857fc0f6d519000012'
|
||||||
@PlansID: '524b7b517fc0f6d51900000d'
|
@PlansID: '524b7b517fc0f6d51900000d'
|
||||||
|
@ProgrammableID: '524b7b5a7fc0f6d51900000e'
|
||||||
urlRoot: '/db/level.component'
|
urlRoot: '/db/level.component'
|
||||||
|
|
||||||
set: (key, val, options) ->
|
set: (key, val, options) ->
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
span.doc-title= doc.title
|
span.doc-title(data-property-name=doc.name)= doc.title
|
|
@ -266,7 +266,7 @@ class InternationalizationNode extends TreemaNode.nodeMap.object
|
||||||
res = super(arguments...)
|
res = super(arguments...)
|
||||||
res = (r for r in res when r[0] isnt '-')
|
res = (r for r in res when r[0] isnt '-')
|
||||||
res
|
res
|
||||||
|
|
||||||
populateData: ->
|
populateData: ->
|
||||||
super()
|
super()
|
||||||
if Object.keys(@data).length is 0
|
if Object.keys(@data).length is 0
|
||||||
|
@ -286,7 +286,12 @@ class InternationalizationNode extends TreemaNode.nodeMap.object
|
||||||
@workingSchema.props = (prop for prop,_ of @parent.schema.properties when prop isnt 'i18n')
|
@workingSchema.props = (prop for prop,_ of @parent.schema.properties when prop isnt 'i18n')
|
||||||
|
|
||||||
for i18nProperty in @workingSchema.props
|
for i18nProperty in @workingSchema.props
|
||||||
i18nChildSchema.properties[i18nProperty] = @parent.schema.properties[i18nProperty]
|
parentSchemaProperties = @parent.schema.properties ? {}
|
||||||
|
for extraSchemas in [@parent.schema.oneOf, @parent.schema.anyOf]
|
||||||
|
for extraSchema in extraSchemas ? []
|
||||||
|
for prop, schema of extraSchema?.properties ? {}
|
||||||
|
parentSchemaProperties[prop] ?= schema
|
||||||
|
i18nChildSchema.properties[i18nProperty] = parentSchemaProperties[i18nProperty]
|
||||||
return i18nChildSchema
|
return i18nChildSchema
|
||||||
#this must be filled out in order for the i18n node to work
|
#this must be filled out in order for the i18n node to work
|
||||||
|
|
||||||
|
|
|
@ -336,6 +336,7 @@ module.exports = class InventoryView extends CocoView
|
||||||
gearByLevel =
|
gearByLevel =
|
||||||
'dungeons-of-kithgard': {feet: 'simple-boots'}
|
'dungeons-of-kithgard': {feet: 'simple-boots'}
|
||||||
'gems-in-the-deep': {feet: 'simple-boots'}
|
'gems-in-the-deep': {feet: 'simple-boots'}
|
||||||
|
'forgetful-gemsmith': {feet: 'simple-boots'}
|
||||||
'shadow-guard': {feet: 'simple-boots'}
|
'shadow-guard': {feet: 'simple-boots'}
|
||||||
'true-names': {feet: 'simple-boots', 'right-hand': 'longsword'}
|
'true-names': {feet: 'simple-boots', 'right-hand': 'longsword'}
|
||||||
'the-raised-sword': {feet: 'simple-boots', 'right-hand': 'longsword', torso: 'leather-tunic'}
|
'the-raised-sword': {feet: 'simple-boots', 'right-hand': 'longsword', torso: 'leather-tunic'}
|
||||||
|
@ -345,9 +346,11 @@ module.exports = class InventoryView extends CocoView
|
||||||
'lowly-kithmen': {feet: 'simple-boots', 'right-hand': 'longsword', 'programming-book': 'programmaticon-i', eyes: 'crude-glasses'}
|
'lowly-kithmen': {feet: 'simple-boots', 'right-hand': 'longsword', 'programming-book': 'programmaticon-i', eyes: 'crude-glasses'}
|
||||||
'closing-the-distance': {feet: 'simple-boots', 'right-hand': 'longsword', torso: 'leather-tunic', eyes: 'crude-glasses'}
|
'closing-the-distance': {feet: 'simple-boots', 'right-hand': 'longsword', torso: 'leather-tunic', eyes: 'crude-glasses'}
|
||||||
'the-final-kithmaze': {feet: 'simple-boots', 'right-hand': 'longsword', torso: 'leather-tunic', 'programming-book': 'programmaticon-i', eyes: 'crude-glasses'}
|
'the-final-kithmaze': {feet: 'simple-boots', 'right-hand': 'longsword', torso: 'leather-tunic', 'programming-book': 'programmaticon-i', eyes: 'crude-glasses'}
|
||||||
'kithgard-gates': {feet: 'simple-boots', 'right-hand': 'builders-hammer'}
|
'kithgard-gates': {feet: 'simple-boots', 'right-hand': 'builders-hammer', torso: 'leather-tunic'}
|
||||||
'defense-of-plainswood': {feet: 'simple-boots', 'right-hand': 'builders-hammer'}
|
'defense-of-plainswood': {feet: 'simple-boots', 'right-hand': 'builders-hammer'}
|
||||||
# TODO: figure out leather boots for plainswood (or next one?)
|
'winding-trail': {feet: 'leather-boots', 'right-hand': 'builders-hammer'}
|
||||||
|
'thornbush-farm': {feet: 'leather-boots', 'right-hand': 'builders-hammer', eyes: 'crude-glasses'}
|
||||||
|
'a-fiery-trap': {feet: 'leather-boots', 'right-hand': 'builders-hammer', eyes: 'crude-glasses'}
|
||||||
return unless necessaryGear = gearByLevel[@options.levelID]
|
return unless necessaryGear = gearByLevel[@options.levelID]
|
||||||
if @inserted
|
if @inserted
|
||||||
if @supermodel.finished()
|
if @supermodel.finished()
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
I18NEditModelView = require './I18NEditModelView'
|
I18NEditModelView = require './I18NEditModelView'
|
||||||
Level = require 'models/Level'
|
Level = require 'models/Level'
|
||||||
|
LevelComponent = require 'models/LevelComponent'
|
||||||
|
|
||||||
module.exports = class I18NEditLevelView extends I18NEditModelView
|
module.exports = class I18NEditLevelView extends I18NEditModelView
|
||||||
id: "i18n-edit-level-view"
|
id: "i18n-edit-level-view"
|
||||||
|
@ -25,24 +26,33 @@ module.exports = class I18NEditLevelView extends I18NEditModelView
|
||||||
if i18n = doc.i18n
|
if i18n = doc.i18n
|
||||||
@wrapRow "Guide article name", ['name'], doc.name, i18n[lang]?.name, ['documentation', 'specificArticles', index]
|
@wrapRow "Guide article name", ['name'], doc.name, i18n[lang]?.name, ['documentation', 'specificArticles', index]
|
||||||
@wrapRow "'#{doc.name}' description", ['description'], doc.description, i18n[lang]?.description, ['documentation', 'specificArticles', index], 'markdown'
|
@wrapRow "'#{doc.name}' description", ['description'], doc.description, i18n[lang]?.description, ['documentation', 'specificArticles', index], 'markdown'
|
||||||
|
|
||||||
# sprite dialogues
|
# sprite dialogues
|
||||||
for script, scriptIndex in @model.get('scripts') ? []
|
for script, scriptIndex in @model.get('scripts') ? []
|
||||||
for noteGroup, noteGroupIndex in script.noteChain ? []
|
for noteGroup, noteGroupIndex in script.noteChain ? []
|
||||||
for spriteCommand, spriteCommandIndex in noteGroup.sprites ? []
|
for spriteCommand, spriteCommandIndex in noteGroup.sprites ? []
|
||||||
pathPrefix = ['scripts', scriptIndex, 'noteChain', noteGroupIndex, 'sprites', spriteCommandIndex, 'say']
|
pathPrefix = ['scripts', scriptIndex, 'noteChain', noteGroupIndex, 'sprites', spriteCommandIndex, 'say']
|
||||||
|
|
||||||
if i18n = spriteCommand.say?.i18n
|
if i18n = spriteCommand.say?.i18n
|
||||||
if spriteCommand.say.text
|
if spriteCommand.say.text
|
||||||
@wrapRow "Sprite text", ['text'], spriteCommand.say.text, i18n[lang]?.text, pathPrefix, 'markdown'
|
@wrapRow "Sprite text", ['text'], spriteCommand.say.text, i18n[lang]?.text, pathPrefix, 'markdown'
|
||||||
if spriteCommand.say.blurb
|
if spriteCommand.say.blurb
|
||||||
@wrapRow "Sprite blurb", ['blurb'], spriteCommand.say.blurb, i18n[lang]?.blurb, pathPrefix
|
@wrapRow "Sprite blurb", ['blurb'], spriteCommand.say.blurb, i18n[lang]?.blurb, pathPrefix
|
||||||
|
|
||||||
for response, responseIndex in spriteCommand.say?.responses ? []
|
for response, responseIndex in spriteCommand.say?.responses ? []
|
||||||
if i18n = response.i18n
|
if i18n = response.i18n
|
||||||
@wrapRow "Response button", ['text'], response.text, i18n[lang]?.text, pathPrefix.concat(['responses', responseIndex])
|
@wrapRow "Response button", ['text'], response.text, i18n[lang]?.text, pathPrefix.concat(['responses', responseIndex])
|
||||||
|
|
||||||
# victory modal
|
# victory modal
|
||||||
if i18n = @model.get('victory')?.i18n
|
if i18n = @model.get('victory')?.i18n
|
||||||
@wrapRow "Victory text", ['body'], @model.get('victory').body, i18n[lang]?.body, ['victory'], 'markdown'
|
@wrapRow "Victory text", ['body'], @model.get('victory').body, i18n[lang]?.body, ['victory'], 'markdown'
|
||||||
|
|
||||||
|
# code comments
|
||||||
|
for thang, thangIndex in @model.get('thangs') ? []
|
||||||
|
for component, componentIndex in thang.components ? []
|
||||||
|
continue unless component.original is LevelComponent.ProgrammableID
|
||||||
|
for methodName, method of component.config?.programmableMethods ? {}
|
||||||
|
if (i18n = method.i18n) and (context = method.context)
|
||||||
|
for key, value of context
|
||||||
|
path = ['thangs', thangIndex, 'components', componentIndex, 'config', 'programmableMethods', methodName]
|
||||||
|
@wrapRow "Code comment", ["context", key], value, i18n[lang]?.context[key], path
|
||||||
|
|
|
@ -105,7 +105,7 @@ module.exports = class DocFormatter
|
||||||
while spokenLanguage
|
while spokenLanguage
|
||||||
spokenLanguage = spokenLanguage.substr 0, spokenLanguage.lastIndexOf('-') if fallingBack?
|
spokenLanguage = spokenLanguage.substr 0, spokenLanguage.lastIndexOf('-') if fallingBack?
|
||||||
if spokenLanguageContext = @doc.i18n[spokenLanguage]?.context
|
if spokenLanguageContext = @doc.i18n[spokenLanguage]?.context
|
||||||
context = spokenLanguageContext
|
context = _.merge context, spokenLanguageContext
|
||||||
break
|
break
|
||||||
fallingBack = true
|
fallingBack = true
|
||||||
obj[prop] = _.template val, context if context
|
obj[prop] = _.template val, context if context
|
||||||
|
|
|
@ -22,6 +22,8 @@ module.exports = class Spell
|
||||||
@levelType = options.level.get('type', true)
|
@levelType = options.level.get('type', true)
|
||||||
|
|
||||||
p = options.programmableMethod
|
p = options.programmableMethod
|
||||||
|
@commentI18N = p.i18n
|
||||||
|
@commentContext = p.context
|
||||||
@languages = p.languages ? {}
|
@languages = p.languages ? {}
|
||||||
@languages.javascript ?= p.source
|
@languages.javascript ?= p.source
|
||||||
@name = p.name
|
@name = p.name
|
||||||
|
@ -61,6 +63,18 @@ module.exports = class Spell
|
||||||
setLanguage: (@language) ->
|
setLanguage: (@language) ->
|
||||||
#console.log 'setting language to', @language, 'so using original source', @languages[language] ? @languages.javascript
|
#console.log 'setting language to', @language, 'so using original source', @languages[language] ? @languages.javascript
|
||||||
@originalSource = @languages[language] ? @languages.javascript
|
@originalSource = @languages[language] ? @languages.javascript
|
||||||
|
# Translate comments chosen spoken language.
|
||||||
|
return unless @commentContext
|
||||||
|
context = $.extend true, {}, @commentContext
|
||||||
|
if @commentI18N
|
||||||
|
spokenLanguage = me.get 'preferredLanguage'
|
||||||
|
while spokenLanguage
|
||||||
|
spokenLanguage = spokenLanguage.substr 0, spokenLanguage.lastIndexOf('-') if fallingBack?
|
||||||
|
if spokenLanguageContext = @commentI18N[spokenLanguage]?.context
|
||||||
|
context = _.merge context, spokenLanguageContext
|
||||||
|
break
|
||||||
|
fallingBack = true
|
||||||
|
@originalSource = _.template @originalSource, context
|
||||||
|
|
||||||
addThang: (thang) ->
|
addThang: (thang) ->
|
||||||
if @thangs[thang.id]
|
if @thangs[thang.id]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue