allow to overide locale method __() to all object

This commit is contained in:
Xuan Sang LE 2018-03-10 22:46:28 +01:00
parent 6367c321da
commit 702a83df6a
7 changed files with 24 additions and 16 deletions

View File

@ -3,13 +3,12 @@ class FormatedString
@values = []
return unless args
@values[i] = args[i] for i in [0..args.length - 1]
toString: ()->
@
toString: () ->
@__()
__: () ->
me = @
return __(@fs).replace /{(\d+)}/g, (match, number) ->
return @fs.l().replace /{(\d+)}/g, (match, number) ->
return if typeof me.values[number] != 'undefined' then me.values[number] else match
hash: () ->
@__().hash()
@ -25,7 +24,12 @@ class FormatedString
format: () ->
args = arguments
@values[i] = args[i] for i in [0..args.length - 1]
Object.defineProperty Object.prototype, '__',
value: () ->
return @toString()
enumerable: false
writable: true
String.prototype.hash = () ->
hash = 5381
@ -66,8 +70,12 @@ String.prototype.f = () ->
String.prototype.__ = () ->
match = @match(/^__\((.*)\)$/)
return window.__(match[1]) if match
return match[1].l() if match
return @
String.prototype.l = () ->
_API = window.OS.API
_API.lang[@] = @ unless _API.lang[@]
return _API.lang[@]
# language directive
this.__ = () ->
@ -75,9 +83,8 @@ this.__ = () ->
args = arguments
return "Undefined" unless args.length > 0
d = args[0]
_API.lang[d] = d unless _API.lang[d]
return _API.lang[d] unless args.length > 1
return String.prototype.format.apply d, (args[i] for i in [1 .. args.length - 1])
d.l()
return new FormatedString d, (args[i] for i in [1 .. args.length - 1])
Date.prototype.toString = () ->
dd = @getDate()

View File

@ -408,7 +408,7 @@ self.OS.GUI =
_GUI.buildSystemMenu()
# push startup services
# TODO: get services list from user setting
#_GUI.pushServices (v for v in _OS.setting.system.startup.services)
_GUI.pushServices (v for v in _OS.setting.system.startup.services)
(_GUI.launch a) for a in _OS.setting.system.startup.apps
#_GUI.launch "DummyApp"
# initDM

View File

@ -65,7 +65,8 @@ self.OS.API.handler =
path = "#{_REST}/system/application"
auth: (c) ->
p = "#{_REST}/system/auth"
_API.post p, {}, c, () ->
_API.post p, {}, c, (e, s) ->
console.log e, s
alert __("Resource not found: {0}", p)
login: (d, c) ->
p = "#{_REST}/system/login"

View File

@ -4,7 +4,7 @@
<li class = "afx-window-close" onclick = {close}></li>
<li if = {minimizable == true} class = "afx-window-minimize" onclick = {minimize}></li>
<li if = {resizable == true} class = "afx-window-maximize" onclick={maximize}></li>
<li ref = "dragger" class = "afx-window-title">{ apptitle?apptitle.toString().__():apptitle }</li>
<li ref = "dragger" class = "afx-window-title">{ apptitle?apptitle.__():apptitle }</li>
</ul>
<div class = "afx-clear"></div>
<div ref = "content" class = "afx-window-content">

View File

@ -2,7 +2,7 @@
<span style = {color?"color:" + color:""} >
<i if={iconclass} class = {iconclass} ></i>
<i if={icon} class="icon-style" style = { "background: url("+icon+");background-size: 100% 100%;background-repeat: no-repeat;" }></i>
{ text?text.toString().__():"" }
{ text?text.__():"" }
</span>
<script>
this.iconclass = opts.iconclass

View File

@ -61,7 +61,7 @@ class CodeBlock extends this.OS.GUI.BaseApplication
menu = [{
text: "File",
child: [
{ text: "__(New)", dataid: "#{@name}-New", shortcut: "A-N" },
{ text: __("New"), dataid: "#{@name}-New", shortcut: "A-N" },
{ text: "__(Open)", dataid: "#{@name}-Open", shortcut: "A-O" },
{ text: "__(Save)", dataid: "#{@name}-Save", shortcut: "C-S" },
{ text: "__(Save as)", dataid: "#{@name}-Saveas", shortcut: "A-W" }

View File

@ -62,8 +62,8 @@ class PushNotification extends this.OS.GUI.BaseService
icon: o.data.icon,
iconclass: o.data.iconclass,
closable: true }
console.log o.data.s
console.log o.data.e
#console.log o.data.s
#console.log o.data.e
@mlist.unshift d, true
@notifeed d