Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
V
VIPSLogic
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
VIPS
VIPSLogic
Commits
75644b33
Commit
75644b33
authored
9 months ago
by
Lene Wasskog
Browse files
Options
Downloads
Patches
Plain Diff
feat: Map from unsupported locale 'no' or 'nn', to 'nb'
parent
21b2ddd1
No related branches found
No related tags found
1 merge request
!184
feat: Map from unsupported locale 'no' or 'nn', to 'nb'
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/no/nibio/vips/logic/i18n/LocalizationFilter.java
+24
-6
24 additions, 6 deletions
...ain/java/no/nibio/vips/logic/i18n/LocalizationFilter.java
with
24 additions
and
6 deletions
src/main/java/no/nibio/vips/logic/i18n/LocalizationFilter.java
+
24
−
6
View file @
75644b33
...
...
@@ -20,9 +20,10 @@ package no.nibio.vips.logic.i18n;
import
com.ibm.icu.util.ULocale
;
import
java.io.IOException
;
import
java.util.
Arrays
;
import
java.util.
HashMap
;
import
java.util.List
;
import
static
java
.
util
.
stream
.
Collectors
.
toList
;
import
java.util.Map
;
import
javax.servlet.Filter
;
import
javax.servlet.FilterChain
;
import
javax.servlet.FilterConfig
;
...
...
@@ -31,7 +32,6 @@ import javax.servlet.ServletRequest;
import
javax.servlet.ServletResponse
;
import
javax.servlet.http.HttpServletRequest
;
import
no.nibio.vips.i18n.LanguageUtil
;
import
no.nibio.vips.logic.util.SystemTime
;
/**
* This filter checks if there are any changes in locale requests, and
...
...
@@ -43,6 +43,12 @@ import no.nibio.vips.logic.util.SystemTime;
public
class
LocalizationFilter
implements
Filter
{
private
List
<
ULocale
>
availableLocales
;
private
static
final
Map
<
String
,
String
>
LOCALE_MAPPING
=
new
HashMap
<>();
static
{
LOCALE_MAPPING
.
put
(
"no"
,
"nb"
);
LOCALE_MAPPING
.
put
(
"nn"
,
"nb"
);
}
@Override
public
void
init
(
FilterConfig
filterConfig
)
throws
ServletException
{
...
...
@@ -63,8 +69,8 @@ public class LocalizationFilter implements Filter{
}*/
ULocale
currentLocale
=
SessionLocaleUtil
.
getCurrentLocale
((
HttpServletRequest
)
request
);
ULocale
browserRequestedLocale
=
ULocale
.
forLocale
(((
HttpServletRequest
)
request
).
getLocale
()
);
String
userRequestedLocaleStr
=
((
HttpServletRequest
)
request
)
.
getParameter
(
"userRequestedLocale"
);
ULocale
browserRequestedLocale
=
getBrowserRequestedLocale
(
request
);
String
userRequestedLocaleStr
=
request
.
getParameter
(
"userRequestedLocale"
);
ULocale
userRequestedLocale
=
userRequestedLocaleStr
!=
null
?
new
ULocale
(
userRequestedLocaleStr
)
:
null
;
/*
...
...
@@ -110,7 +116,19 @@ public class LocalizationFilter implements Filter{
chain
.
doFilter
(
request
,
response
);
}
/**
* Get locale from request. Map from unsupported 'no' and 'nn', to 'nb'.
*
* @param request The request from which to get the locale
* @return A locale which is supported by the system
*/
private
static
ULocale
getBrowserRequestedLocale
(
ServletRequest
request
)
{
ULocale
locale
=
ULocale
.
forLocale
(
request
.
getLocale
());
String
language
=
locale
.
getLanguage
();
String
mappedLanguage
=
LOCALE_MAPPING
.
getOrDefault
(
language
,
language
);
return
new
ULocale
(
mappedLanguage
);
}
@Override
public
void
destroy
()
{
...
...
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