Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
osticket
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
docker
osticket
Commits
d90093a3
Commit
d90093a3
authored
9 years ago
by
Jared Hancock
Browse files
Options
Downloads
Patches
Plain Diff
topic: Sort localized list case insensitively
parent
f3244b5b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/class.i18n.php
+22
-0
22 additions, 0 deletions
include/class.i18n.php
include/class.topic.php
+4
-11
4 additions, 11 deletions
include/class.topic.php
with
26 additions
and
11 deletions
include/class.i18n.php
+
22
−
0
View file @
d90093a3
...
@@ -461,6 +461,28 @@ class Internationalization {
...
@@ -461,6 +461,28 @@ class Internationalization {
return
$locales
;
return
$locales
;
}
}
static
function
sortKeyedList
(
$list
,
$case
=
false
)
{
global
$cfg
;
if
(
$cfg
&&
function_exists
(
'collator_create'
))
{
$coll
=
Collator
::
create
(
$cfg
->
getPrimaryLanguage
());
if
(
!
$case
)
$coll
->
setStrength
(
Collator
::
TERTIARY
);
// UASORT is necessary to preserve the keys
uasort
(
$list
,
function
(
$a
,
$b
)
use
(
$coll
)
{
return
$coll
->
compare
(
$a
,
$b
);
});
}
else
{
if
(
!
$case
)
uasort
(
$list
,
function
(
$a
,
$b
)
{
return
strcmp
(
mb_strtoupper
(
$a
),
mb_strtoupper
(
$b
));
});
else
// Really only works on ascii names
asort
(
$list
);
}
return
$list
;
}
static
function
bootstrap
()
{
static
function
bootstrap
()
{
require_once
INCLUDE_DIR
.
'class.translation.php'
;
require_once
INCLUDE_DIR
.
'class.translation.php'
;
...
...
This diff is collapsed.
Click to expand it.
include/class.topic.php
+
4
−
11
View file @
d90093a3
...
@@ -347,10 +347,12 @@ implements TemplateVariable {
...
@@ -347,10 +347,12 @@ implements TemplateVariable {
$requested_names
[
$id
]
=
$n
;
$requested_names
[
$id
]
=
$n
;
}
}
//
XXX:
If localization requested and the current locale is not the
// If localization requested and the current locale is not the
// primary, the list may need to be sorted. Caching is ok here,
// primary, the list may need to be sorted. Caching is ok here,
// because the locale is not going to be changed within a single
// because the locale is not going to be changed within a single
// request.
// request.
if
(
$localize
)
return
Internationalization
::
sortKeyedList
(
$requested_names
);
return
$requested_names
;
return
$requested_names
;
}
}
...
@@ -520,16 +522,7 @@ implements TemplateVariable {
...
@@ -520,16 +522,7 @@ implements TemplateVariable {
if
(
!
(
$names
=
static
::
getHelpTopics
(
false
,
true
,
false
)))
if
(
!
(
$names
=
static
::
getHelpTopics
(
false
,
true
,
false
)))
return
;
return
;
if
(
$cfg
&&
function_exists
(
'collator_create'
))
{
$names
=
Internationalization
::
sortKeyedList
(
$names
);
$coll
=
Collator
::
create
(
$cfg
->
getPrimaryLanguage
());
// UASORT is necessary to preserve the keys
uasort
(
$names
,
function
(
$a
,
$b
)
use
(
$coll
)
{
return
$coll
->
compare
(
$a
,
$b
);
});
}
else
{
// Really only works on English names
asort
(
$names
);
}
$update
=
array_keys
(
$names
);
$update
=
array_keys
(
$names
);
foreach
(
$update
as
$idx
=>&
$id
)
{
foreach
(
$update
as
$idx
=>&
$id
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment