This is the simplest, most global approach to I18N. It does complete I18N on the server side by setting the locale on each request, based on the value in the http header.

If we go this route, I can remove the parameter as a parameter on the metadata plugin



To test this:

curl -H "Content-Type:application/json" -H "Accept:applicaton/json" -H "Accept-Language:uk" --negotiate -u : --cacert /etc/ipa/ca.crt -d '{"method":"plugin_metadata","params":[[""],{"all":true}],"id":6}' -X POST http://localhost:8888/ipa/json | grep label


And note that is should work for any RPC.  For example


:"user_find","params":[[""],{"all":true}],"id":6}' -X POST http://localhost:8888/ipa/json | grep summary % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 13114 0 13114 0 58 42902 189 --:--:-- --:--:-- --:--:-- 42996 "summary": "\u0432\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043e \u0432\u0456\u0434\u043f\u043e\u0432\u0456\u0434\u043d\u0456\u0441\u0442\u044c 7 \u043a\u043e\u0440\u0438\u0441\u0442\u0443\u0432\u0430\u0447\u0456\u0432", [ayo...@ipa freeipa]$ curl -H "Content-Type:application/json" -H "Accept:applicaton/json" -H "Accept-Language:es" --negotiate -u : --cacert /etc/ipa/ca.crt -d '{"method":"user_find","params":[[""],{"all":true}],"id":6}' -X POST http://localhost:8888/ipa/json | grep summary % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 12917 0 12917 0 58 48572 218 --:--:-- --:--:-- --:--:-- 48743
        "summary": "7 usuarios coincidentes",
>From a072a382825ca98028dcdc0eb333163752fd4e3f Mon Sep 17 00:00:00 2001
From: Adam Young <ayo...@redhat.com>
Date: Mon, 20 Sep 2010 14:11:32 -0400
Subject: [PATCH] I18N of RPC

Uses the HTTP header to perform set the LANG environment variable in Python, used for the gettext translations

 Author:    adam <ayo...@redhat.com>
---
 ipaserver/rpcserver.py |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/ipaserver/rpcserver.py b/ipaserver/rpcserver.py
index 71d5544..f17fe7d 100644
--- a/ipaserver/rpcserver.py
+++ b/ipaserver/rpcserver.py
@@ -34,7 +34,7 @@ from ipalib.util import make_repr
 from ipalib.compat import json
 from wsgiref.util import shift_path_info
 import base64
-
+import os
 _not_found_template = """<html>
 <head>
 <title>404 Not Found</title>
@@ -192,7 +192,10 @@ class WSGIExecutioner(Executioner):
         result = None
         error = None
         _id = None
+        lang= os.environ['LANG']
         try:
+            if ('HTTP_ACCEPT_LANGUAGE' in environ):
+                os.environ['LANG']=environ['HTTP_ACCEPT_LANGUAGE']
             if (
                 environ.get('CONTENT_TYPE', '').startswith(self.content_type)
                 and environ['REQUEST_METHOD'] == 'POST'
@@ -211,6 +214,8 @@ class WSGIExecutioner(Executioner):
                 'non-public: %s: %s', e.__class__.__name__, str(e)
             )
             error = InternalError()
+        finally:
+            os.environ['LANG']=lang
         return self.marshal(result, error, _id)
 
     def simple_unmarshal(self, environ):
-- 
1.7.1

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to