Skip to content

Instantly share code, notes, and snippets.

@mackato
Created November 12, 2010 07:05
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mackato/673822 to your computer and use it in GitHub Desktop.
Save mackato/673822 to your computer and use it in GitHub Desktop.
timeago a jQuery plugin Japanese enhancement
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