HelloZeroNet / ZeroNet

ZeroNet - Decentralized websites using Bitcoin crypto and BitTorrent network
https://zeronet.io
Other
18.33k stars 2.27k forks source link

ZeroNet's --debug mode Automatic CoffeeScript -> JavaScript conversion not friendly of i18n #713

Open cxgreat2014 opened 7 years ago

cxgreat2014 commented 7 years ago

coffee script not friendly of i18n, like that:

class Time
  since: (time) ->
    now = +(new Date) / 1000
    secs = now - time
    if secs < 60
      back = "Just now"
    else if secs < 60 * 60
      back = "#{Math.round(secs / 60)} minutes ago"
    else if secs < 60 * 60 * 24
      back = "#{Math.round(secs / 60 / 60)} hours ago"
    else if secs < 60 * 60 * 24 * 3
      back = "#{Math.round(secs / 60 / 60 / 24)} days ago"
    else
      back = "on " + @date(time)
    back = back.replace(/1 ([a-z]+)s/, "1 $1") # 1 days ago fix
    return back

  date: (timestamp, format = "short") ->
    parts = new Date(timestamp * 1000)
    if format == "short"
      display = (parts.getFullYear() + "nian" + String(parts.getMonth() + 1) + "yue" + parts.getDay() + "ri")
    else
      display = parts.toTimeString()
    return display

  timestamp: (date = "") ->
    if date == "now" or date == ""
      return parseInt(+(new Date) / 1000)
    else
      return parseInt(Date.parse(date) / 1000)

# Get elistamated read time for post
  readtime: (text) ->
    chars = text.length
    if chars > 1500
      return parseInt(chars / 1500) + " min read"
    else
      return "less than 1 min read"

window.Time = new Time

success image but if I change it to Chinese...BOOM.

class Time
  since: (time) ->
    now = +(new Date) / 1000
    secs = now - time
    if secs < 60
      back = "刚才"
    else if secs < 60 * 60
      back = "#{Math.round(secs / 60)} 分钟前"
    else if secs < 60 * 60 * 24
      back = "#{Math.round(secs / 60 / 60)} 小时前"
    else if secs < 60 * 60 * 24 * 3
      back = "#{Math.round(secs / 60 / 60 / 24)} 天之前"
    else
      back = "on " + @date(time)
    back = back.replace(/1 ([a-z]+)s/, "1 $1") # 1 days ago fix
    return back

  date: (timestamp, format = "short") ->
    parts = new Date(timestamp * 1000)
    if format == "short"
      display = (parts.getFullYear() + "年" + String(parts.getMonth() + 1) + "月" + parts.getDay() + "日")
    else
      display = parts.toTimeString()
    return display

  timestamp: (date = "") ->
    if date == "now" or date == ""
      return parseInt(+(new Date) / 1000)
    else
      return parseInt(Date.parse(date) / 1000)

# Get elistamated read time for post
  readtime: (text) ->
    chars = text.length
    if chars > 1500
      return parseInt(chars / 1500) + " min read"
    else
      return "less than 1 min read"

window.Time = new Time

image Um....How to slove it? or ZeroBundle should upgrade Coffee Script?

HelloZeroNet commented 7 years ago

I have just tried and it's compiled for me without any error

cxgreat2014 commented 7 years ago

win7 x64, with a new zerobundle, editor is webstorm, disabled webstorm's file watcher I have no idea about this .....

weakish commented 7 years ago

@cxgreat2014 Try to compile your Time.coffee via coffee -c. So we can know which line causes the compile error.

cxgreat2014 commented 7 years ago

image @weakish not work, coffee.wsf(85, 6) file can't open

cxgreat2014 commented 7 years ago

???I try to not use ZeroNet --debug command and use npm install -g coffee-script and coffee -c Time.coffee image success... maybe it's zeronet's coffee script BUG

HelloZeroNet commented 7 years ago

Yeah, i forgot i have a node based coffeescript compiler (it's faster) (type %s | tools\coffee-node\bin\node.exe tools\coffee-node\bin\coffee --no-header -s -p)

I will try whats happens with the wsh-based one.

Alternative you can edit the all.js directly or make ZeroBlog multilanguage by adding

 "translate": [
  "index.html",
  "js/all.js"
 ],

to content.json, then creating languages/zh.json and specify what you want to replace. (see ZeroTalk for example)

cxgreat2014 commented 7 years ago

@HelloZeroNet Ok, thanks, I'm using a dirt hack with replace DebugMedia.py's command with set command = 'coffee -p ' + file_path_escaped, it's work :) :+1:

cxgreat2014 commented 7 years ago

I think use moment.js in ZeroBlog is better than Time.coffee, because moment.js is i18n

weakish commented 7 years ago

Tested with the bundled coffee on Windows, it compiles.

In the screenshot, it seems you are using a coffee in the root directory of your site. It is strange. On my machine, the path is D:\ZeroBundle\ZeroNet\tools\coffee\coffee.cmd.

ysc3839 commented 7 years ago

I have this problem too. But I installed the node version CoffeeScript. It seems that it's caused by Windows' cscript.exe.

cxgreat2014 commented 7 years ago

@weakish I just copy D:\ZeroBundle\ZeroNet\tools\coffee\coffee.cmd to my site dir