Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/js
diff options
context:
space:
mode:
authorBryan Berry <bryan@olenepal.org>2010-01-18 15:01:42 (GMT)
committer Bryan Berry <bryan@olenepal.org>2010-01-18 15:01:42 (GMT)
commitd1cf37f15429f51844003619f41be23653479186 (patch)
treec48afd46855da8c5076a5c2bb449946f510bdc6c /js
parenta30259202ae2bc7ffad2b89bde0bbb8eccba9a32 (diff)
added Karma.convertNumToLocale method along w/ unit tests
Diffstat (limited to 'js')
-rwxr-xr-xjs/karma.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/js/karma.js b/js/karma.js
index 75a8fd3..3d8c6f8 100755
--- a/js/karma.js
+++ b/js/karma.js
@@ -215,6 +215,36 @@ Karma.shuffle = function (oldList) {
return newList;
};
+
+/**
+ * Converts a number to numerals in the specified locale. Currently only
+ * supports Nepali
+ * @param {Number} Number to be converted
+ * @param {locale} locale that number should be converted to
+ * @returns {String} Unicode string for localized numeral
+ */
+Karma.convertNumToLocale = function(num, locale){
+ //48 is the base for western numerals
+ var convertDigit = function(digit){
+
+ var numBase = 48;
+ var prefix = "u00";
+
+ if (locale === "ne"){
+ prefix = "u0";
+ numBase = 2406;
+ }
+
+ return '\\' + prefix +
+ (numBase + parseInt(digit)).toString(16);
+ };
+
+ var charArray = num.toString().split("").map(convertDigit);
+ console.log(charArray.join(''));
+ return eval('"' + charArray.join('') + '"');
+};
+
+
// Below are geometry and math helper methods
/**