Skip to content

Commit

Permalink
Add localeCode config
Browse files Browse the repository at this point in the history
  • Loading branch information
FlipWarthog committed Oct 17, 2023
1 parent 4e91dcc commit a7f4793
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion components/lib/calendar/Calendar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
2 changes: 1 addition & 1 deletion components/lib/carousel/Carousel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions components/lib/config/PrimeVue.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ import { VirtualScrollerPassThroughOptions } from '../virtualscroller';
export interface PrimeVueConfiguration {
ripple?: boolean;
inputStyle?: string;
localeCode?: string;
locale?: PrimeVueLocaleOptions;
filterMatchModeOptions?: any;
zIndex?: PrimeVueZIndexOptions;
Expand Down
1 change: 1 addition & 0 deletions components/lib/config/PrimeVue.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { inject, reactive } from 'vue';
export const defaultOptions = {
ripple: false,
inputStyle: 'outlined',
localeCode: 'en',
locale: {
startsWith: 'Starts with',
contains: 'Contains',
Expand Down
4 changes: 2 additions & 2 deletions components/lib/datatable/DataTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion components/lib/dataview/DataView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion components/lib/galleria/GalleriaThumbnails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions components/lib/treetable/TreeTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions components/lib/utils/ObjectUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '') {
Expand Down
2 changes: 2 additions & 0 deletions doc/configuration/locale/SetLocaleDoc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default {
code1: {
basic: `
app.use(PrimeVue, {
localeCode: 'es',
locale: {
accept: 'Aceptar',
reject: 'Rechazar',
Expand All @@ -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";
}
Expand Down

0 comments on commit a7f4793

Please sign in to comment.