1

My JSF facelet looks like this:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0  Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui">
    <h:head>
        <title>Facelet Title</title>
    </h:head>
    <h:body>      
     <p:calendar mode="inline" 
                 locale="zh_CN" 
                 showButtonPanel="true" 
                 navigator="true" />
   </h:body> 
</html>

When I run it, the rendered calendar's language is English, while I want the language change to be Chinese Simplified. How can I achieve this ?

My Primefaces's version is 4.0 and the JSF version is 2.2.

Konstantin Yovkov
  • 62,134
  • 8
  • 100
  • 147
bob
  • 13
  • 6

2 Answers2

1

PrimeFaces only provides English translations, add the corresponding locales in a javascript file to your application to support more locales for components that can be localize, such as the calender.

PrimeFaces.locales['zh_CN'] = {
   closeText: '关闭',
   prevText: '上个月',
   nextText: '下个月',
   currentText: '今天',
   monthNames: ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'],
   monthNamesShort: ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'],
   dayNames: ['星期日','星期一','星期二','星期三','星期四','星期五','星期六'],
   dayNamesShort: ['日','一','二','三','四','五','六'],
   dayNamesMin: ['日','一','二','三','四','五','六'],
   weekHeader: '周',
   firstDay: 1,
   isRTL: false,
   showMonthAfterYear: true,
   yearSuffix: '', // 年
   timeOnlyTitle: '仅时间',
   timeText: '时间',
   hourText: '时',
   minuteText: '分',
   secondText: '秒',
   ampm: false,
   month: '月',
   week: '周',
   day: '日',
   allDayText : '全天' };

Include the above in a file, lets call it calendarLabels_zh_CN.js

Then

<h:outputScript name="js/calendarLabels_zh_CN.js"/>

More information

Danubian Sailor
  • 1
  • 38
  • 145
  • 223
Hatem Alimam
  • 9,968
  • 4
  • 44
  • 56
  • I've removed 'target="head"' from h:outputScript because it made your script to be loaded **before** primefaces.js, which was incorrect. Probably connected with http://stackoverflow.com/questions/17582476/houtputscript-with-target-head-not-working-with-primefaces-3-5 – Danubian Sailor Feb 11 '14 at 13:46
0

After many attempts, including target="head" one, I found the correct answer to my similar Primefaces Locales problem: put the Javascript code at the end of the facelet file just before </h:body> tag.

I am using PrimeFaces 4.0 and JSF 2.1.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Is that post a comment to Hatem Alimam's answer? What javascript code do you have in mind? – Danubian Sailor Feb 10 '14 at 10:39
  • It's an answer to Bob's question. I tried the answer provided by Hatem Alimam without success. So I wrote the Javascript code defined in calendarLabels_zh_CN.js directly at the end of my XHTML file and it was ok. It's also fine to use
     at the end of the XHTML file.
    – Yann Tanquerel Feb 11 '14 at 13:31
  • "TypeError: PrimeFaces.locales is undefined", yes? I've identified it, it's the problem with 'target="head"', you should remove it. – Danubian Sailor Feb 11 '14 at 13:44