Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve collation #266

Closed
alanfgh opened this issue May 15, 2014 · 3 comments
Closed

Improve collation #266

alanfgh opened this issue May 15, 2014 · 3 comments
Milestone

Comments

@alanfgh
Copy link
Contributor

alanfgh commented May 15, 2014

Currently, the list of language names is probably sorted (collated) by ASCII character order, since, as sacredceltic has pointed out, the languages beginning with non-ASCII characters end up at the bottom of the list. Ideally, the sort order would be determined by the UI language. But if this is not possible, at least it should be possible to choose a collation that would be better across all languages.

Collation could also affect the list of tags and several other sets of strings other than language names.

@trang
Copy link
Member

trang commented May 16, 2014

The place to fix it: https://github.com/Tatoeba/tatoeba2/blob/master/app/views/helpers/languages.php#L240

This is the line that does the sort:

asort($this->__languages);

Maybe this will give the solution to sort properly: http://stackoverflow.com/questions/2897924/sort-array-with-special-characters-in-php

@alanfgh
Copy link
Contributor Author

alanfgh commented May 17, 2014

Some notes after looking at those pages:

(1) One person wrote:

"I ended up installing the French language pack to my server and using the following :

setlocale(LC_COLLATE, 'fr_CA.utf8');
asort($array, SORT_LOCALE_STRING);"

which worked.

(2) The syntax here is a bit different, but it may be a better solution:

http://docs.php.net/manual/en/collator.asort.php

We should create the collator when the UI language is chosen and refer to it thereafter.

(3) See also:

http://docs.php.net/manual/en/class.collator.php

@jiru
Copy link
Member

jiru commented May 18, 2014

Quoting http://php.net/setlocale:

The locale information is maintained per process, not per thread. If you are running PHP on a multithreaded server API like IIS or Apache on Windows, you may experience sudden changes in locale settings while a script is running, though the script itself never called setlocale(). This happens due to other scripts running in different threads of the same process at the same time, changing the process-wide locale using setlocale().

So don’t use setlocale(). Ever.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants