HelloZeroNet / HelloZeroNet/ZeroNet

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

Open
#713 11 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
18.8k
Forks
2.3k
PR merge metrics
No merged PRs in 30d

Description

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](https://cloud.githubusercontent.com/assets/15062548/21390661/005675ca-c7c3-11e6-8d60-f3da5428dade.png)
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](https://cloud.githubusercontent.com/assets/15062548/21390739/59740c8a-c7c3-11e6-836b-94c9c73e3bdc.png)
Um....How to slove it? or ZeroBundle should upgrade Coffee Script?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.