diff --git a/components/lib/calendar/Calendar.vue b/components/lib/calendar/Calendar.vue index 05c1763037..33f6459823 100755 --- a/components/lib/calendar/Calendar.vue +++ b/components/lib/calendar/Calendar.vue @@ -2669,7 +2669,7 @@ export default { let innerHTML = ''; if (this.responsiveOptions) { - const comparer = ObjectUtils.localeComparator(); + const comparer = ObjectUtils.localeComparator(this.$primevue.config.localeCode); let responsiveOptions = [...this.responsiveOptions].filter((o) => !!(o.breakpoint && o.numMonths)).sort((o1, o2) => -1 * comparer(o1.breakpoint, o2.breakpoint)); for (let i = 0; i < responsiveOptions.length; i++) { diff --git a/components/lib/carousel/Carousel.vue b/components/lib/carousel/Carousel.vue index cd189b170c..b7296bf0d0 100755 --- a/components/lib/carousel/Carousel.vue +++ b/components/lib/carousel/Carousel.vue @@ -548,7 +548,7 @@ export default { if (this.responsiveOptions && !this.isUnstyled) { let _responsiveOptions = [...this.responsiveOptions]; - const comparer = ObjectUtils.localeComparator(); + const comparer = ObjectUtils.localeComparator(this.$primevue.config.localeCode); _responsiveOptions.sort((data1, data2) => { const value1 = data1.breakpoint; diff --git a/components/lib/config/PrimeVue.d.ts b/components/lib/config/PrimeVue.d.ts index e17d8727be..a2afa23305 100644 --- a/components/lib/config/PrimeVue.d.ts +++ b/components/lib/config/PrimeVue.d.ts @@ -100,6 +100,7 @@ import { VirtualScrollerPassThroughOptions } from '../virtualscroller'; export interface PrimeVueConfiguration { ripple?: boolean; inputStyle?: string; + localeCode?: string; locale?: PrimeVueLocaleOptions; filterMatchModeOptions?: any; zIndex?: PrimeVueZIndexOptions; diff --git a/components/lib/config/PrimeVue.js b/components/lib/config/PrimeVue.js index 5ed9836529..408c2d0487 100644 --- a/components/lib/config/PrimeVue.js +++ b/components/lib/config/PrimeVue.js @@ -4,6 +4,7 @@ import { inject, reactive } from 'vue'; export const defaultOptions = { ripple: false, inputStyle: 'outlined', + localeCode: 'en', locale: { startsWith: 'Starts with', contains: 'Contains', diff --git a/components/lib/datatable/DataTable.vue b/components/lib/datatable/DataTable.vue index 931878a38b..b6463ede70 100755 --- a/components/lib/datatable/DataTable.vue +++ b/components/lib/datatable/DataTable.vue @@ -540,7 +540,7 @@ export default { resolvedFieldData.set(item, ObjectUtils.resolveFieldData(item, this.d_sortField)); } - const comparer = ObjectUtils.localeComparator(); + const comparer = ObjectUtils.localeComparator(this.$primevue.config.localeCode); data.sort((data1, data2) => { let value1 = resolvedFieldData.get(data1); @@ -575,7 +575,7 @@ export default { multisortField(data1, data2, index) { const value1 = ObjectUtils.resolveFieldData(data1, this.d_multiSortMeta[index].field); const value2 = ObjectUtils.resolveFieldData(data2, this.d_multiSortMeta[index].field); - const comparer = ObjectUtils.localeComparator(); + const comparer = ObjectUtils.localeComparator(this.$primevue.config.localeCode); if (value1 === value2) { return this.d_multiSortMeta.length - 1 > index ? this.multisortField(data1, data2, index + 1) : 0; diff --git a/components/lib/dataview/DataView.vue b/components/lib/dataview/DataView.vue index b1e14fc3e1..73ebb45ee4 100755 --- a/components/lib/dataview/DataView.vue +++ b/components/lib/dataview/DataView.vue @@ -110,7 +110,7 @@ export default { sort() { if (this.value) { const value = [...this.value]; - const comparer = ObjectUtils.localeComparator(); + const comparer = ObjectUtils.localeComparator(this.$primevue.config.localeCode); value.sort((data1, data2) => { let value1 = ObjectUtils.resolveFieldData(data1, this.sortField); diff --git a/components/lib/galleria/GalleriaThumbnails.vue b/components/lib/galleria/GalleriaThumbnails.vue index 5df896fad3..1e2e16c384 100755 --- a/components/lib/galleria/GalleriaThumbnails.vue +++ b/components/lib/galleria/GalleriaThumbnails.vue @@ -438,7 +438,7 @@ export default { if (this.responsiveOptions && !this.isUnstyled) { this.sortedResponsiveOptions = [...this.responsiveOptions]; - const comparer = ObjectUtils.localeComparator(); + const comparer = ObjectUtils.localeComparator(this.$primevue.config.localeCode); this.sortedResponsiveOptions.sort((data1, data2) => { const value1 = data1.breakpoint; diff --git a/components/lib/treetable/TreeTable.vue b/components/lib/treetable/TreeTable.vue index 28f03c5c72..2f94a94b07 100755 --- a/components/lib/treetable/TreeTable.vue +++ b/components/lib/treetable/TreeTable.vue @@ -429,7 +429,7 @@ export default { }, sortNodesSingle(nodes) { let _nodes = [...nodes]; - const comparer = ObjectUtils.localeComparator(); + const comparer = ObjectUtils.localeComparator(this.$primevue.config.localeCode); _nodes.sort((node1, node2) => { const value1 = ObjectUtils.resolveFieldData(node1.data, this.d_sortField); @@ -455,7 +455,7 @@ export default { multisortField(node1, node2, index) { const value1 = ObjectUtils.resolveFieldData(node1.data, this.d_multiSortMeta[index].field); const value2 = ObjectUtils.resolveFieldData(node2.data, this.d_multiSortMeta[index].field); - const comparer = ObjectUtils.localeComparator(); + const comparer = ObjectUtils.localeComparator(this.$primevue.config.localeCode); if (value1 === value2) { return this.d_multiSortMeta.length - 1 > index ? this.multisortField(node1, node2, index + 1) : 0; diff --git a/components/lib/utils/ObjectUtils.js b/components/lib/utils/ObjectUtils.js index d8fe31173f..26bb10a8a3 100755 --- a/components/lib/utils/ObjectUtils.js +++ b/components/lib/utils/ObjectUtils.js @@ -328,9 +328,9 @@ export default { return result; }, - localeComparator() { + localeComparator(localeCode) { //performance gain using Int.Collator. It is not recommended to use localeCompare against large arrays. - return new Intl.Collator(undefined, { numeric: true }).compare; + return new Intl.Collator(localeCode, { numeric: true }).compare; }, nestedKeys(obj = {}, parentKey = '') { diff --git a/doc/common/apidoc/index.json b/doc/common/apidoc/index.json index f87df58a5d..d855c17f93 100644 --- a/doc/common/apidoc/index.json +++ b/doc/common/apidoc/index.json @@ -14005,6 +14005,13 @@ "type": "string", "default": "" }, + { + "name": "localeCode", + "optional": true, + "readonly": false, + "type": "string", + "default": "" + }, { "name": "locale", "optional": true, diff --git a/doc/configuration/locale/SetLocaleDoc.vue b/doc/configuration/locale/SetLocaleDoc.vue index cce74b3e0b..40139c6f75 100644 --- a/doc/configuration/locale/SetLocaleDoc.vue +++ b/doc/configuration/locale/SetLocaleDoc.vue @@ -17,6 +17,7 @@ export default { code1: { basic: ` app.use(PrimeVue, { + localeCode: 'es', locale: { accept: 'Aceptar', reject: 'Rechazar', @@ -34,6 +35,7 @@ export default defineComponent({ setup() { const changeToSpanish = () => { const primevue = usePrimeVue(); + primevue.config.localeCode = "es"; primevue.config.locale.accept = "Aceptar"; primevue.config.locale.reject = "Rechazar"; }