Skip to content

Commit b2caba5

Browse files
committed
Add locales api endpoint
1 parent 6d4c64f commit b2caba5

5 files changed

Lines changed: 32 additions & 10 deletions

File tree

red/api/flows.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
**/
16-
var express = require('express');
17-
var fs = require("fs");
18-
var events = require("../events");
19-
var path = require("path");
2016

2117
var log = require("../log");
2218
var redNodes = require("../nodes");

red/api/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var flows = require("./flows");
2525
var library = require("./library");
2626
var info = require("./info");
2727
var theme = require("./theme");
28+
var locales = require("./locales");
2829

2930
var auth = require("./auth");
3031
var needsPermission = auth.needsPermission;
@@ -85,6 +86,8 @@ function init(adminApp,storage) {
8586
adminApp.get("/nodes/:mod/:set",needsPermission("nodes.read"),nodes.getSet);
8687
adminApp.put("/nodes/:mod/:set",needsPermission("nodes.write"),nodes.putSet);
8788

89+
adminApp.get(/^\/locales\/(.+?)\/(.*)$/,needsPermission("nodes.read"),locales.get);
90+
8891
// Library
8992
library.init(adminApp);
9093
adminApp.post(new RegExp("/library/flows\/(.*)"),needsPermission("library.write"),library.post);

red/api/locales.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Copyright 2015 IBM Corp.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
**/
16+
var i18n = require("../i18n");
17+
18+
module.exports = {
19+
get: function(req,res) {
20+
var lang = req.params[0];
21+
var namespace = req.params[1];
22+
var catalog = i18n.catalog(namespace,lang);
23+
if (catalog) {
24+
res.json(catalog);
25+
} else {
26+
res.send(404);
27+
}
28+
}
29+
}

red/api/nodes.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
**/
16-
var express = require('express');
17-
var fs = require("fs");
18-
var path = require("path");
19-
var when = require('when');
20-
21-
var events = require("../events");
2216
var redNodes = require("../nodes");
2317
var comms = require("../comms");
2418
var server = require("../server");

test/red/api/locales_spec.js

Whitespace-only changes.

0 commit comments

Comments
 (0)