The Locale API allows setting i18n and l7n options globally for the components.
By using the locale, addLocale, updateLocaleOption, updateLocaleOptions, localeOption and localeOptions methods, locale objects can be used in the whole application or in certain pages.
import { locale, addLocale, updateLocaleOption, updateLocaleOptions, localeOption, localeOptions } from 'primereact/api';
The current locale can be set with locale method.
locale('en');
New locale values can be added using addLocale method for the application.
addLocale('es', {
firstDayOfWeek: 1,
dayNames: ['domingo', 'lunes', 'martes', 'miércoles', 'jueves', 'viernes', 'sábado'],
dayNamesShort: ['dom', 'lun', 'mar', 'mié', 'jue', 'vie', 'sáb'],
dayNamesMin: ['D', 'L', 'M', 'X', 'J', 'V', 'S'],
monthNames: ['enero', 'febrero', 'marzo', 'abril', 'mayo', 'junio', 'julio', 'agosto', 'septiembre', 'octubre', 'noviembre', 'diciembre'],
monthNamesShort: ['ene', 'feb', 'mar', 'abr', 'may', 'jun', 'jul', 'ago', 'sep', 'oct', 'nov', 'dic'],
today: 'Hoy',
clear: 'Limpiar'
});
locale('es');
Locale values can be changed dynamically. (Note: please don't forget to update main or current component with state management or forceUpdate method of React.)
<Button label="EN" onClick={() => locale('en')} />
<Button label="ES" onClick={() => locale('es')} />
Ready to use settings for locales are available at the community supported PrimeLocale repository. We'd appreciate if you could contribute to this repository with pull requests and share it with the rest of the community.
Name | Parameters | Return | Description |
---|---|---|---|
locale | currentLocale: string | {locale: string, options: object} | Used to determine the current locale value. Returns the name and values of the current locale. |
addLocale | locale: string, options: object | Used to add a new locale. | |
updateLocaleOption | key: string, value: any, locale: string | Used to change the option value of a current or specific locale. | |
updateLocaleOptions | options: object, locale: string | Used to change the option values of a current or specific locale. | |
localeOption | key: string, locale: string | Used to get the option value of a current or specific locale. | |
localeOptions | locale: string | Used to get the option values of a current or specific locale. |
Key | Value |
---|---|
startsWith | Starts with |
contains | Contains |
notContains | Not contains |
endsWith | Ends with |
equals | Equals |
notEquals | Not equals |
noFilter | No Filter |
filter | Filter |
lt | Less than |
lte | Less than or equal to |
gt | Greater than |
gte | Greater than or equal to |
dateIs | Date is |
dateIsNot | Date is not |
dateBefore | Date is before |
dateAfter | Date is after |
custom | Custom |
clear | Clear |
apply | Apply |
matchAll | Match All |
matchAny | Match Any |
addRule | Add Rule |
removeRule | Remove Rule |
accept | Yes |
reject | No |
choose | Choose |
upload | Upload |
cancel | Cancel |
close | Close |
dayNames | ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] |
dayNamesShort | ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'] |
dayNamesMin | ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'] |
monthNames | ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] |
monthNamesShort | ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] |
today | Today |
weekHeader | Wk |
firstDayOfWeek | 0 |
dateFormat | mm/dd/yy |
weak | Weak |
medium | Medium |
strong | Strong |
passwordPrompt | Enter a password |
emptyFilterMessage | No available options |
emptyMessage | No results found |
aria.trueLabel | True |
aria.falseLabel | False |
aria.nullLabel | Not Selected |
aria.pageLabel | Page |
aria.firstPageLabel | First Page |
aria.lastPageLabel | Last Page |
aria.nextPageLabel | Next Page |
aria.previousPageLabel | Previous Page |
aria.selectLabel | Select |
aria.unselectLabel | Unselect |
aria.expandLabel | Expand |
aria.collapseLabel | Collapse |
Built-in component themes created by the PrimeReact Theme Designer.
Premium themes are only available exclusively for PrimeReact Theme Designer subscribers and therefore not included in PrimeReact core.
Beautifully crafted premium create-react-app application templates by the PrimeTek design team.