Created
November 12, 2010 07:05
-
-
Save mackato/673822 to your computer and use it in GitHub Desktop.
timeago a jQuery plugin Japanese enhancement
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function convertWithLang(timeAgo, lang) { | |
if (lang == "ja") | |
return toJa(timeAgo); | |
return timeAgo; | |
} | |
function convert(timeAgo, dict, strip) { | |
var delim = " "; | |
var arr = timeAgo.split(delim); | |
if (strip) | |
delim = ""; | |
return jQuery.map(arr, function(key, i) { | |
var replace = dict[key]; | |
return replace ? replace : key; | |
}).join(delim); | |
} | |
function toJa(timeAgo) { | |
var dict = { | |
"about": "約", | |
"a": "1", | |
"an": "1", | |
"minute": "分", | |
"minutes": "分", | |
"hour": "時間", | |
"hours": "時間", | |
"ago": "前", | |
"day": "日", | |
"days": "日", | |
"month": "月", | |
"months": "月", | |
"year": "年", | |
"years": "年" | |
}; | |
toJa = function(str) { | |
if (str == "less than a minute") | |
return "1分未満"; | |
return convert(str, dict, true); | |
} | |
return toJa(timeAgo); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment