Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added more functions to transifex.js with tests.

  • Loading branch information...
commit b816f3810b73807f1b8d3e56979d6b69b13ac46c 1 parent 8d8197e
@toolness toolness authored
Showing with 88 additions and 0 deletions.
  1. +20 −0 bin/transifex.js
  2. +68 −0 test/node-tap/test-transifex.js
View
20 bin/transifex.js
@@ -2,10 +2,30 @@ const BASE_URL = 'https://www.transifex.com/api/2/project/';
var request = require('request');
+var toTransifexLocale = exports.toTransifexLocale = function(locale) {
+ var parts = locale.split(/[-_]/);
+ if (parts.length >= 2)
+ return parts[0].toLowerCase() + "_" + parts[1].toUpperCase();
+ return parts[0].toLowerCase();
+};
+
var toBundleLocale = exports.toBundleLocale = function(locale) {
return locale.toLowerCase().replace(/_/g, '-');
};
+var parseProjectDetails = exports.parseProjectDetails = function(project) {
+ var details = {};
+ project.resources.forEach(function(resource) {
+ var parts = resource.name.split('/');
+ details[resource.name] = {
+ slug: resource.slug,
+ path: parts.slice(0, -1).join('/'),
+ moduleName: parts[parts.length-1]
+ };
+ });
+ return details;
+};
+
var toBundleMetadata = exports.toBundleMetadata = function(resource) {
var metadata = {};
resource.available_languages.forEach(function(language) {
View
68 test/node-tap/test-transifex.js
@@ -98,6 +98,74 @@ var resourceDetails = {
"slug": "slowparse-errorsnlsforbidjs"
};
+// Example response from a URL of the form:
+//
+// /api/2/project/<project_slug>/?details
+//
+// For more information, see:
+//
+// http://help.transifex.com/features/api/index.html#project-instance-methods
+
+var projectDetails = {
+ "feed": "",
+ "source_language_code": "en",
+ "description": "World's friendliest HTML editor.",
+ "created": "2013-01-23 14:45:08",
+ "trans_instructions": "",
+ "tags": "",
+ "teams": [
+ "en_US"
+ ],
+ "maintainers": [
+ {
+ "username": "toolness"
+ }
+ ],
+ "private": false,
+ "slug": "friendlycode",
+ "anyone_submit": false,
+ "outsource": null,
+ "fill_up_resources": false,
+ "bug_tracker": "",
+ "owner": {
+ "username": "toolness"
+ },
+ "homepage": "",
+ "long_description": "",
+ "resources": [
+ {
+ "slug": "slowparse-errorsnlsforbidjs",
+ "name": "slowparse-errors/nls/forbidjs"
+ }
+ ],
+ "name": "Friendlycode"
+};
+
+test("toBundleLocale() works", function(t) {
+ t.equal(transifex.toBundleLocale("en_US"), "en-us", "with region");
+ t.equal(transifex.toBundleLocale("en-us"), "en-us", "idempotency");
+ t.equal(transifex.toBundleLocale("en"), "en", "without region");
+ t.end();
+});
+
+test("toTransifexLocale() works", function(t) {
+ t.equal(transifex.toTransifexLocale("en-us"), "en_US", "with region");
+ t.equal(transifex.toTransifexLocale("en_US"), "en_US", "idempotency");
+ t.equal(transifex.toTransifexLocale("en"), "en", "without region");
+ t.end();
+});
+
+test("parseProjectDetails() works", function(t) {
+ t.deepEqual(transifex.parseProjectDetails(projectDetails), {
+ "slowparse-errors/nls/forbidjs": {
+ slug: "slowparse-errorsnlsforbidjs",
+ path: "slowparse-errors/nls",
+ moduleName: "forbidjs"
+ }
+ });
+ t.end();
+});
+
test("toBundleMetadata() works", function(t) {
t.deepEqual(transifex.toBundleMetadata(resourceDetails), {
"root": true,
Please sign in to comment.
Something went wrong with that request. Please try again.