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