Scirra / Construct-bugs

Public bug report submissions for Construct 3 and Construct Animate. Please read the guidelines then click the 'Issues' tab to get started.
https://www.construct.net
107 stars 83 forks source link

Use localeCompare to sort in non-English languages #8010

Closed XHXIAIEIN closed 3 months ago

XHXIAIEIN commented 3 months ago

Problem description

Currently, the editor use encoding order when sorting. But in non-English, usually not used this order, but is according to the dictionary order of the local language.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare

Attach a .c3p

issue-dictionary-sort.c3p.zip

Steps to reproduce

  1. Variable list
  2. Layout name

Observed result

for example in Chinese

const names = ['上海', '北京', '深圳', '杭州', '西安', '成都', '云南']
names.sort()

// ['上海', '云南', '北京', '成都', '杭州', '深圳', '西安']

Expected result

const names = ['上海', '北京', '深圳', '杭州', '西安', '成都', '云南']
names.sort((a, b) => a.localeCompare(b));

// ['北京', '成都', '杭州', '上海', '深圳', '西安', '云南']

and this

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator

const pinyin = new Intl.Collator("zh", {collation: "pinyin", usage: "search", caseFirst: "upper", numeric: true, sensitivity: "base"})

pinyin.compare(a.name, b.name);

More details

Affected browsers/platforms:

First affected release:

System details

View details PASTE HERE
AshleyScirra commented 3 months ago

Sorting is used in a great deal of places all across the editor, and each case probably needs evaluating to determine whether locale sorting is appropriate or not. Therefore this is probably quite a significant amount of upgrade/refactoring work, and I think this is better categorised as a feature request.