gvSIG feature requests #4153
Add i18n support in Scripting libs
Status: | Closed | % Done: | 0% | |
---|---|---|---|---|
Priority: | Normal | Spent time: | - | |
Assignee: | Joaquín del Cerro Murciano | |||
Category: | Scripting | |||
Target version: | 2.3.0-2429 (rev. org.gvsig.desktop-2.0.135, NOT USABLE) | |||
gvSIG version: | 2.3.0 | Add-on resolve version: | ||
Keywords: | i18n, jython, script, translation | Add-on resolve build: | ||
Has patch: | Proyecto: | |||
Add-on name: | Unknown | Hito: | ||
Add-on version: |
Description
Adding i18n support in Scripting would allow to share scripts with translations. I attach a Scripting package containing an example of i18n strings translation in a Jython script. The main advantage is that the properties files are packed together with the script for easy distribution. Feel free to add (and eventually rename) the getResources() method in the Scripting libs.
Associated revisions
refs #4153, sobrecargado el metodo addResourceFamily del I18nManager para aceptar un File (folder) en lugar de un ClassLoader de forma que sea mas comodo de invocar desde el entorno de scripting.
refs #4153, actualizado el DefaultI18nManager con el nuevo metodo addResourceFamily.
refs #4153 actualizada la version de org.gvsig.tools
History
#1 Updated by Joaquín del Cerro Murciano over 8 years ago
- Target version changed from 2.3.0-2447-final (rev. org.gvsig.desktop-2.0.153) to 2.3.0-2426 (rev. org.gvsig.desktop-2.0.132, NOT USABLE)
- Assignee set to Joaquín del Cerro Murciano
La gestión de las traducciones en gvSIG se hace a través de la clase "I18nManager".
Se accede a las cadenas de traducción a través del método getTranslation y se registran nuevas cadenas de traducción con el método addResourceFamily. Desde scripting deberían usarse estos mecanismos para que las traducciones en los scripts se integren con las de gvSIG.
Desde jython seria algo como:
from org.gvsig.tools import ToolsLocator def main(*args): i18nManager = ToolsLocator.getI18nManager() print i18nManager.getTranslation("cancelar")
De esta forma accederíamos a la traducción para el idioma corriente de la clave "cancelar".
Si quisiésemos registrar nuevas cadenas de traducción lo podríamos hacer con:
from org.gvsig.tools import ToolsLocator def main(*args): i18nManager = ToolsLocator.getI18nManager() i18nManager.addResourceFamily("text", script.getResource("i18n")) print i18nManager.getTranslation("cancelar")
Esto añadiría unas nuevas cadenas de traducción a gvSIG, buscándolas en la carpeta "i18n" junto al script que se esta ejecutando, y los ficheros con las traducciones tendrían la forma :
- text.properties
- text_en.properties
- text_it.properties
El método addResourceFamily recibía un ClassLoader, que es lioso de usar desde Jython, así que he sobrecargado el método para que reciba la carpeta en la que e encuentran los ficheros de traducciones.
#2 Updated by Joaquín del Cerro Murciano over 8 years ago
- Status changed from New to Fixed
#3 Updated by Antonio Falciano over 8 years ago
Hi Joaquín,
your last comment sounds like an interesting blog post in order to show this scripting capability. Sharing a scripting package complete of translations will be an easy task with gvSIG 2.3. Thank you very much!
#4 Updated by Antonio Falciano over 8 years ago
- Target version changed from 2.3.0-2426 (rev. org.gvsig.desktop-2.0.132, NOT USABLE) to 2.3.0-2447-final (rev. org.gvsig.desktop-2.0.153)
- Status changed from Fixed to New
It seems that the addResourceFamily doesn't work here using e.g. the "hello_world" string:
from org.gvsig.tools import ToolsLocator def main(*args): i18nManager = ToolsLocator.getI18nManager() i18nManager.addResourceFamily("text", script.getResource("i18n")) print i18nManager.getTranslation("hello_world")
Note that the "cancelar" i18n string is always available in the application.
#5 Updated by Antonio Falciano over 8 years ago
- Target version changed from 2.3.0-2447-final (rev. org.gvsig.desktop-2.0.153) to 2.3.0-2429 (rev. org.gvsig.desktop-2.0.135, NOT USABLE)
- Status changed from New to Closed
Restarting gvSIG the above example it works fine now. Thank you very much.