Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to localize p:captcha

I would like to create a localization for PrimeFaces <p:captcha> component. I know how to localize validation error messages by using requiredMessage or validatorMessage attributes as follows:

<p:captcha label="Captcha" theme="clean" requiredMessage="#{msg['primefaces.captcha.INVALID']}" validatorMessage="#{msg['primefaces.tree.REQUIRED']}"/>

The problem is that I don't know how to localize e.g. labels (as depicted below)

Example validation

So I need to localize points 1) and 2) and tooltips which are showed when user hovers any of buttons. It would be also nice if reCaptcha could use some kind of localized dictionary (3rd point) but I doubt that it's possible and it's really optional. I know that reCaptcha has few supported languages but mine (pl - polish) is unfortunately not supported...

like image 752
Disper Avatar asked Mar 13 '26 13:03

Disper


1 Answers

Just add a language attribute to the captcha tag

<p:captcha language="pl" />

If you have a session bean that stores the user language you can use that too, for example:

<p:captcha language="#{userSessionBean.locale}" />

The bean:

@ManagedBean
@SessionScoped
public class UserSessionBean {
    private Locale locale;

    public Locale getLocale(){ return locale; }
    public void setLocale(Locale locale) { this.locale = locale; }
}
like image 139
José Roberto Araújo Júnior Avatar answered Mar 16 '26 04:03

José Roberto Araújo Júnior



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!