Skip to content

Commit

Permalink
Merge pull request #70 from ramusus/v0.2.2_i18n
Browse files Browse the repository at this point in the history
translated product edit placeholders, improve getLabelsFor getMessagesFor functions, translated schema labels
  • Loading branch information
Aaron Judd authored and aaronjudd committed Jan 18, 2015
2 parents 5c64933 + 05a8c82 commit df4cddd
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 18 deletions.
26 changes: 12 additions & 14 deletions packages/reaction-core/client/helpers/i18n/i18n.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
# get i18n messages for updating autoform labels from simple schema
#
###
getLabelsFor = (schema, name, sessionLanguage) ->
getLabelsFor = (schema, name) ->
labels = {}
for fieldName in schema._schemaKeys
i18n_key = name.charAt(0).toLowerCase() + name.slice(1) + "." + fieldName.split(".$").join("")
# console.log "schema: " + name + " fieldName: " + fieldName + " i18nkey: " + i18n_key
translation = i18n.t(i18n_key)
# console.debug "schema: #{name} fieldName: #{fieldName} i18n_key: #{i18n_key} translation: #{translation}"
if new RegExp('string').test(translation) isnt true and translation isnt i18n_key
# schema._schema[fieldName].label = i18n.t(i18n_key)
labels[fieldName] = translation
Expand All @@ -38,7 +38,7 @@ getLabelsFor = (schema, name, sessionLanguage) ->
# (3) Use schema-specific message for type
#
###
getMessagesFor = (schema, name, sessionLanguage) ->
getMessagesFor = (schema, name) ->
messages = {}
for message of SimpleSchema._globalMessages
i18n_key = "globalMessages" + "." + message
Expand Down Expand Up @@ -78,26 +78,25 @@ Meteor.startup ->
, {}

$.i18n.init {
lng: sessionLanguage
fallbackLng: 'en'
ns: "core"
resStore: resources
# debug: true
lng: sessionLanguage
fallbackLng: 'en'
ns: "core"
resStore: resources
# debug: true
},(t)->
# update labels and messages for autoform,schemas
for schema, ss of ReactionCore.Schemas
ss.labels getLabelsFor(ss, schema, sessionLanguage)
ss.messages getMessagesFor(ss, schema, sessionLanguage)
ss.labels getLabelsFor(ss, schema)
ss.messages getMessagesFor(ss, schema)

#re-init all i18n
i18nextDep.changed()

# reactive translations in all templates
Template.onRendered () ->
t = @
t.autorun () ->
@autorun () =>
i18nextDep.depend() #rerun whenever language changes and we re-init $.i18n
$elements = t.$("[data-i18n]")
$elements = @$("[data-i18n]")
$elements.i18n() if typeof $elements.i18n is "function"
return
return
Expand All @@ -122,7 +121,6 @@ Template.registerHelper "i18n", (i18n_key, camelCaseString) ->
result = new Handlebars.SafeString(i18n.t(i18n_key))
return result


###
# return shop /locale specific currency format (ie: $)
###
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<template name="productDetailEdit">
{{#if condition type "eq" "textarea"}}
<p class="product-detail-edit {{field}}-edit">
<textarea class="{{field}}-edit-input" placeholder="add a product {{camelToSpace field}}">{{value}}</textarea>
<textarea class="{{field}}-edit-input" placeholder="{{i18n 'productDetailEdit' field }}">{{value}}</textarea>
</p>
{{else}}
<div class="product-detail-edit {{field}}-edit">
<input type="text" value="{{value}}" class="{{field}}-edit-input" placeholder="product {{camelToSpace field}}"/>
<input type="text" value="{{value}}" class="{{field}}-edit-input" placeholder="{{i18n 'productDetailEdit' field }}"/>
</div>
{{/if}}
<span class="product-detail-message" id="{{field}}-message"></span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
{{#if userHasRole "admin"}}
<div id="dropzone" class="dropzone">
<input name="files" id="files" class="hidden" type="file" multiple/>
<div class="btn btn-default btn-block" id="btn-upload">Drop file to upload</div>
<div class="btn btn-default btn-block" id="btn-upload" data-i18n="productDetail.dropFile">Drop file to upload</div>
</div>
{{/if}}
</template>
6 changes: 6 additions & 0 deletions packages/reaction-core/private/data/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@
"selectOption": "Select an option before adding to cart",
"addedToCart": "added"
},
"productDetailEdit": {
"title": "Product title",
"pagetitle": "Product page title",
"vendor": "Product vendor",
"description": "Add a product description"
},
"variantList": {
"moreOptions": "There are more options available for this selection.",
"createVariant": "Create Variant"
Expand Down
22 changes: 21 additions & 1 deletion packages/reaction-core/private/data/i18n/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,27 @@
"productDeleteError": "Произошла ошибка во время удаления товара ",
"publishFirst": "Опубликуйте товар прежде чем добавить в корзину.",
"selectOption": "Выберите вариант прежде чем добавить в корзину",
"addedToCart": "добавлено"
"addedToCart": "добавлено",
"dropFile": "Перетащите фото для загрузки"
},
"productDetailEdit": {
"title": "Название",
"pagetitle": "Другое название",
"vendor": "Производитель",
"description": "Добавьте описание товара"
},
"productVariant": {
"inventoryQuantity": "Количество",
"title": "Название",
"price": "Цена",
"optionTitle": "Опция",
"barcode": "Штрих-код",
"compareAtPrice": "Рекомендованная цена",
"fulfillmentService": "Fulfillment service",
"weight": "Вес",
"inventoryManagement": "Inventory Tracking",
"inventoryPolicy": "Не продавать, если кончается",
"lowInventoryWarningThreshold": "Предупреждать когда меньше, чем"
},
"variantList": {
"moreOptions": "Есть еще варианты доступные для этого выбора.",
Expand Down

0 comments on commit df4cddd

Please sign in to comment.