mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 09:35:39 -05:00
Added i18n coverage logic to the CocoModel.
This commit is contained in:
parent
54de8482f1
commit
092997bffe
2 changed files with 49 additions and 1 deletions
|
@ -332,6 +332,30 @@ class CocoModel extends Backbone.Model
|
||||||
error: ->
|
error: ->
|
||||||
console.error 'Miserably failed to fetch unnotified achievements', arguments
|
console.error 'Miserably failed to fetch unnotified achievements', arguments
|
||||||
|
|
||||||
CocoModel.pollAchievements = _.debounce CocoModel.pollAchievements, 500
|
CocoModel.pollAchievements = _.debounce CocoModel.pollAchievements, 500
|
||||||
|
|
||||||
|
|
||||||
|
#- Internationalization
|
||||||
|
|
||||||
|
updateI18NCoverage: ->
|
||||||
|
i18nObjects = @findI18NObjects()
|
||||||
|
console.log 'i18n objects', i18nObjects
|
||||||
|
langCodeArrays = (_.keys(i18n) for i18n in i18nObjects)
|
||||||
|
console.log 'lang code arrays', langCodeArrays
|
||||||
|
window.codes = langCodeArrays
|
||||||
|
@set('i18nCoverage', _.intersection(langCodeArrays...))
|
||||||
|
|
||||||
|
findI18NObjects: (data, results) ->
|
||||||
|
data ?= @attributes
|
||||||
|
results ?= []
|
||||||
|
|
||||||
|
if _.isPlainObject(data) or _.isArray(data)
|
||||||
|
for [key, value] in _.pairs data
|
||||||
|
if key is 'i18n'
|
||||||
|
results.push value
|
||||||
|
else if _.isPlainObject(value) or _.isArray(value)
|
||||||
|
@findI18NObjects(value, results)
|
||||||
|
|
||||||
|
return results
|
||||||
|
|
||||||
module.exports = CocoModel
|
module.exports = CocoModel
|
||||||
|
|
|
@ -150,3 +150,27 @@ describe 'CocoModel', ->
|
||||||
else return ready false
|
else return ready false
|
||||||
|
|
||||||
request.response {status:200, responseText: JSON.stringify me}
|
request.response {status:200, responseText: JSON.stringify me}
|
||||||
|
|
||||||
|
describe 'updateI18NCoverage', ->
|
||||||
|
class FlexibleClass extends CocoModel
|
||||||
|
@className: 'Flexible'
|
||||||
|
@schema: {}
|
||||||
|
|
||||||
|
it 'only includes languages for which all objects include a translation', ->
|
||||||
|
m = new FlexibleClass({
|
||||||
|
i18n: { es: {}, fr: {} }
|
||||||
|
prop1: 1
|
||||||
|
prop2: 'string'
|
||||||
|
prop3: true
|
||||||
|
innerObject: {
|
||||||
|
i18n: { es: {}, de: {}, fr: {} }
|
||||||
|
prop4: [
|
||||||
|
{
|
||||||
|
i18n: { es: {} }
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
m.updateI18NCoverage()
|
||||||
|
expect(JSON.stringify(m.get('i18nCoverage'))).toBe('["es"]')
|
Loading…
Reference in a new issue