Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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);
- }
Add Comment
Please, Sign In to add comment