New i18n module with improved resource loading.
parent
03ef9aec42
commit
438fd73b74
|
@ -26,51 +26,50 @@ defaults = {
|
|||
ns: "app"
|
||||
fallbackLng: "en"
|
||||
async: false
|
||||
lng: "en"
|
||||
}
|
||||
|
||||
|
||||
class I18nService extends taiga.Service
|
||||
constructor: (@rootscope, @localeEn) ->
|
||||
constructor: (@rootscope, localesEn) ->
|
||||
@.options = _.clone(defaults, true)
|
||||
@.options.resStore = {
|
||||
en: { app: localesEn }
|
||||
}
|
||||
|
||||
setLanguage: (language) ->
|
||||
options = _.clone(defaults, true)
|
||||
i18n.setLng(language, options)
|
||||
|
||||
i18n.setLng(language)
|
||||
@rootscope.currentLang = language
|
||||
@rootscope.$broadcast("i18n:changeLang", language)
|
||||
|
||||
initialize: (defaultLang="en") ->
|
||||
options = _.clone(defaults, true)
|
||||
options.lng = defaultLang
|
||||
options.resStore = {
|
||||
en: { app: @localeEn }
|
||||
}
|
||||
|
||||
i18n.init(options)
|
||||
initialize: ->
|
||||
i18n.init(@.options)
|
||||
@rootscope.t = i18n.t
|
||||
|
||||
|
||||
I18nDirective = ($rootscope, $i18n) ->
|
||||
link = ($scope, $el, $attrs) ->
|
||||
values = $attrs.tgI18n.split(",")
|
||||
options = $attrs.tgI18nOptions or '{}'
|
||||
values = $attrs.tr.split(",")
|
||||
options = $attrs.trOpts or '{}'
|
||||
|
||||
applyTranslation = ->
|
||||
opts = $scope.$eval(options)
|
||||
|
||||
for v in values
|
||||
if v.indexOf(":") == -1
|
||||
$el.html($scope.t(v, opts))
|
||||
$el.html(_.escape($scope.t(v, opts)))
|
||||
else
|
||||
[ns, v] = v.split(":")
|
||||
$el.attr(ns, $scope.t(v, opts))
|
||||
$el.attr(ns, _.escape($scope.t(v, opts)))
|
||||
|
||||
bindOnce($scope, "t", applyTranslation)
|
||||
$scope.$on("i18n:changeLang", applyTranslation)
|
||||
|
||||
return {link: link}
|
||||
return {
|
||||
link: link
|
||||
restrict: "A"
|
||||
scope: false
|
||||
}
|
||||
|
||||
|
||||
module = angular.module("taigaBase")
|
||||
module.service("$tgI18n", ["$rootScope", "localesEnglish", I18nService])
|
||||
module.directive("tgI18n", ["$rootScope", "$tgI18n", I18nDirective])
|
||||
module.service("$tgI18n", ["$rootScope", "localesEn", I18nService])
|
||||
module.directive("tr", ["$rootScope", "$tgI18n", I18nDirective])
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
a.close(href="", title="close")
|
||||
span.icon.icon-delete
|
||||
form
|
||||
h2.title(tg-i18n="common.new-bulk")
|
||||
h2.title(tr="common.new-bulk")
|
||||
fieldset
|
||||
textarea(cols="200", wrap="off", tg-limit-line-length, tg-i18n="placeholder:common.one-item-line", ng-model="new.bulk", data-required="true", data-linewidth="200")
|
||||
a.button.button-green(href="", tg-i18n="title:common.save")
|
||||
span(tg-i18n="common.save")
|
||||
textarea(cols="200", wrap="off", tg-limit-line-length, tr="placeholder:common.one-item-line", ng-model="new.bulk", data-required="true", data-linewidth="200")
|
||||
a.button.button-green(href="", tr="title:common.save")
|
||||
span(tr="common.save")
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
a.close(href="", title="close")
|
||||
span.icon.icon-delete
|
||||
form
|
||||
h2.title(tg-i18n="common.new-bulk")
|
||||
h2.title(tr="common.new-bulk")
|
||||
fieldset
|
||||
textarea(cols="200", wrap="off", tg-limit-line-length, tg-i18n="placeholder:common.one-item-line", ng-model="form.data", data-required="true")
|
||||
a.button.button-green(href="", tg-i18n="title:common.save")
|
||||
span(tg-i18n="common.save")
|
||||
textarea(cols="200", wrap="off", tg-limit-line-length, tr="placeholder:common.one-item-line", ng-model="form.data", data-required="true")
|
||||
a.button.button-green(href="", tr="title:common.save")
|
||||
span(tr="common.save")
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
a.close(href="", title="close")
|
||||
span.icon.icon-delete
|
||||
form
|
||||
h2.title(tg-i18n="task.title-new")
|
||||
h2.title(tr="task.title-new")
|
||||
fieldset
|
||||
input(type="text", ng-model="task.subject", placeholder="A task subject",
|
||||
data-required="true", data-maxlength="500")
|
||||
|
@ -30,7 +30,7 @@ form
|
|||
|
||||
fieldset.blocking-flag
|
||||
input(type="checkbox", ng-model="task.is_blocked", name="blocked-task", id="blocked-task", ng-value="true")
|
||||
label.blocked(for="blocked-task", tg-i18n="common.blocked")
|
||||
label.blocked(for="blocked-task", tr="common.blocked")
|
||||
|
||||
tg-blocking-message-input(watch="task.is_blocked", ng-model="task.blocked_note")
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
a.close(href="", title="close")
|
||||
span.icon.icon-delete
|
||||
form
|
||||
h2.title(tg-i18n="common.new-bulk")
|
||||
h2.title(tr="common.new-bulk")
|
||||
fieldset
|
||||
textarea(cols="200", wrap="off", tg-limit-line-length, tg-i18n="placeholder:common.one-item-line", ng-model="new.bulk", data-required="true", data-linewidth="200")
|
||||
a.button.button-green(href="", tg-i18n="title:common.save")
|
||||
span(tg-i18n="common.save")
|
||||
textarea(cols="200", wrap="off", tg-limit-line-length, tr="placeholder:common.one-item-line", ng-model="new.bulk", data-required="true", data-linewidth="200")
|
||||
a.button.button-green(href="", tr="title:common.save")
|
||||
span(tr="common.save")
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
a.close(href="", title="close")
|
||||
span.icon.icon-delete
|
||||
form
|
||||
h2.title(tg-i18n="us.title-new")
|
||||
h2.title(tr="us.title-new")
|
||||
fieldset
|
||||
input(type="text", name="subject", ng-model="us.subject", tg-i18n="placeholder:common.subject",
|
||||
input(type="text", name="subject", ng-model="us.subject", tr="placeholder:common.subject",
|
||||
data-required="true", data-maxlength="500")
|
||||
|
||||
fieldset.estimation
|
||||
|
@ -12,7 +12,7 @@ form
|
|||
|
||||
fieldset
|
||||
select(name="status", ng-model="us.status", ng-options="s.id as s.name for s in usStatusList",
|
||||
tg-i18n="placeholder:common.status")
|
||||
tr="placeholder:common.status")
|
||||
|
||||
fieldset
|
||||
div(tg-tag-line, editable="true", ng-model="us.tags")
|
||||
|
@ -24,16 +24,16 @@ form
|
|||
fieldset.team-requirement
|
||||
input(type="checkbox", name="team_requirement", ng-model="us.team_requirement",
|
||||
id="team-requirement", ng-value="true")
|
||||
label.requirement(for="team-requirement", tg-i18n="us.team-requirement")
|
||||
label.requirement(for="team-requirement", tr="us.team-requirement")
|
||||
|
||||
fieldset.client-requirement
|
||||
input(type="checkbox", name="client_requirement", ng-model="us.client_requirement",
|
||||
id="client-requirement", ng-value="true")
|
||||
label.requirement(for="client-requirement", tg-i18n="us.client-requirement")
|
||||
label.requirement(for="client-requirement", tr="us.client-requirement")
|
||||
|
||||
fieldset.blocking-flag
|
||||
input(type="checkbox", name="is_blocked", ng-model="us.is_blocked", id="blocked-us" ng-value="true")
|
||||
label.blocked(for="blocked-us", tg-i18n="common.blocked")
|
||||
label.blocked(for="blocked-us", tr="common.blocked")
|
||||
|
||||
tg-blocking-message-input(watch="us.is_blocked", ng-model="us.blocked_note")
|
||||
|
||||
|
|
Loading…
Reference in New Issue