Browse Source

Load po files and convert them into a JSON bundle

Armin Ronacher 9 years ago
parent
commit
be353560a5
4 changed files with 32 additions and 5 deletions
  1. 5 3
      bin/merge-catalogs
  2. 2 1
      package.json
  3. 17 0
      src/sentry/static/sentry/app/translations.jsx
  4. 8 1
      webpack.config.js

+ 5 - 3
bin/merge-catalogs

@@ -10,12 +10,14 @@ JS_EXTENSIONS = ('.js', '.jsx')
 
 
 def merge_message(msg, frontend_msg):
-    msg.locations = [
+    non_js_locations = [
         (fn, lineno) for fn, lineno in msg.locations
         if not fn.endswith(JS_EXTENSIONS)
-    ] + frontend_msg.locations
-    if not msg.user_comments and frontend_msg.user_comments:
+    ]
+    if (not msg.user_comments or not non_js_locations) \
+       and frontend_msg.user_comments:
         msg.user_comments = frontend_msg.usr_comments
+    msg.locations = non_js_locations + frontend_msg.locations
 
 
 @click.command()

+ 2 - 1
package.json

@@ -53,8 +53,9 @@
   },
   "devDependencies": {
     "babel-core": "5.8.33",
-    "babel-gettext-plugin": "getsentry/babel-gettext-plugin",
+    "babel-gettext-extractor": "^1.0.0",
     "babel-loader": "5.3.3",
+    "po-loader": "^0.3.1",
     "chai": "3.4.1",
     "js-cookie": "2.0.4",
     "karma": "0.13.15",

+ 17 - 0
src/sentry/static/sentry/app/translations.jsx

@@ -0,0 +1,17 @@
+const translations = (function() {
+  var ctx = require.context('../../../locale/', true, /\.po$/);
+  var rv = {};
+  ctx.keys().forEach((translation) => {
+    var langCode = translation.match(/([a-zA-Z_]+)/)[1];
+    rv[langCode] = ctx(translation);
+  });
+  return rv;
+})();
+
+export function getTranslations(language) {
+  return translations[language] || translations.en;
+}
+
+export function translationsExist(language) {
+  return translations[language] !== undefined;
+}

+ 8 - 1
webpack.config.js

@@ -16,6 +16,9 @@ var config = {
   entry: {
     // js
     "app": "app",
+    "translations": [
+      "app/translations"
+    ],
     "vendor": [
       "babel-core/polyfill",
       "bootstrap/js/dropdown",
@@ -55,7 +58,7 @@ var config = {
         include: path.join(__dirname, staticPrefix),
         exclude: /(vendor|node_modules)/,
         query: {
-          plugins: ['babel-gettext-plugin'],
+          plugins: ['babel-gettext-extractor'],
           extra: {
             gettext: {
               fileName: 'build/javascript.po',
@@ -70,6 +73,10 @@ var config = {
           }
         }
       },
+      {
+        test: /\.po$/,
+        loader: 'json!po',
+      },
       {
         test: /\.json$/,
         loader: "json-loader"