Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to I18N PrimeFaces Editor

I cannot work out how to add internationalization to the PrimeFaces Editor (Version 3.2). I need to translate tooltips, texts in comboboxes and change icons of the toolbar. In an old users guide http://www.scribd.com/doc/49595285/46/Editor I found an attribute called "language" but this seems to be kind of disabled or removed for the actual version.

My project setup is JSF 2 with PrimeFaces 3.2 and GlassFish 3.1.2

I'd be very glad if you could show me how I can solve this problem.

Thanks and Kind regards,

Pedro

like image 921
Del Pedro Avatar asked Jan 26 '26 07:01

Del Pedro


2 Answers

JMelnik is right. There is a workaround though!

You can do that by downloading the editor.js file from the primefaces subversion repository: 3_3_1/src/main/resources/META-INF/resources/primefaces/editor/editor.js and place it inside your project's META-INF/resources/primefaces/editor folder.

Now you can edit the file and change it according to you locale. I did it for some of the buttons in pt_BR:

buttons: {
  // name,title,command,popupName (""=use name)
  init:
  "bold,Negrito,|" +
  "italic,Itálico,|" +
  "underline,Sublinhado,|" +
  "strikethrough,Tachado,|" +
  "subscript,Subscrito,|" +
  "superscript,Sobrescrito,|" +
  "font,Fonte,fontname,|" +
  "size,Tamanho da Fonte,fontsize,|" +
  "style,Estilo,formatblock,|" +
  "color,Cor da fonte,forecolor,|" +
  "highlight,Cor de Destaque do Texto,hilitecolor,color|" +
  "removeformat,Remove Formatting,|" +
  "bullets,Marcadores,insertunorderedlist|" +
  "numbering,Numeração,insertorderedlist|" +
  "outdent,Diminuir Recuo,|" +
  "indent,Aumentar Recuo,|" +
  "alignleft,Alinhar à Esquerda,justifyleft|" +
  "center,Centralizar,justifycenter|" +
  "alignright,Alinhar à Direita,justifyright|" +
  "justify,Justificar,justifyfull|" +
  "undo,,|" +
  "redo,,|" +
  "rule,Insert Horizontal Rule,inserthorizontalrule|" +
  "image,Insert Image,insertimage,url|" +
  "link,Insert Hyperlink,createlink,url|" +
  "unlink,Remove Hyperlink,|" +
  "cut,,|" +
  "copy,,|" +
  "paste,,|" +
  "pastetext,Paste as Text,inserthtml,|" +
  "print,,|" +
  "source,Mostrar Código Fonte"
},

A i18n solution for that would be great since this approach won't support multiple locales and make you code depend on specific encoding (as it may use special characters).

like image 71
user793953 Avatar answered Jan 28 '26 22:01

user793953


Analysis

If we look at the PrimeFaces 3.2 documentation, there is no such attribute as language for Editor component and there is nothing mentioned in localization chapter.

PrimeFaces do not provide a way to localize Editor as they do provide for Calendar. And obviously they do provide it for calendar, because it is out of box feature for jQuery datePicker, which caledar is based on.

Outcome

Look for editor.js in PrimeFaces 3.2 sources. There is a section, where all editor buttons are initialized:

buttons: {
   // name,title,command,popupName (""=use name)
   init:
   .....
   "font,,fontname,|" +
   "size,Font Size,fontsize,|" +
   .....
}

There is provided format for separate button setup: name,title,command,popupName. The title part is the one you can make use of.

What you can do, you can build primefaces sources with your own titles provided, or override them in other way I cannot think of.

Help

If you are using maven, you can install customized primefaces in local or centralized repository of your own and use it instead of original dependency.

Lesson

You shouldn't look for old documentation, when you are using newer version. Look for the documentation of the version you are using.

like image 31
JMelnik Avatar answered Jan 28 '26 20:01

JMelnik