-
-
Notifications
You must be signed in to change notification settings - Fork 401
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
OBPIH-6410 Allow configuring country specific localization #4681
Conversation
@awalkowiak Please give me a few days to get to this one. |
@@ -26,9 +26,41 @@ class LocalizationUtil { | |||
return localizationService.currentLocale | |||
} | |||
|
|||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An alternative to this would be to extend the Locale class and give it another constructor but I don't know if there's much advantage of that over what you've done
@@ -1449,7 +1449,7 @@ class ProductService { | |||
|
|||
Product addSynonymToProduct(String productId, String synonymTypeCodeName, String synonymValue, String localeName) { | |||
Product product = Product.get(productId) | |||
Locale locale = localeName ? new Locale(localeName) : null | |||
Locale locale = localeName ? LocalizationUtil.getLocale(localeName) : null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a question to be resolved here, but I'm wondering if there's a fancier way to do this so that we don't need to bake all this localization logic into our services.
It'd be awesome if we could mark a Domain field as "localized" and then whenever we do a look up on that field it'd automatically also search for the synonyms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I guess this is a more Synonyms related topic suiting for a TD discovery or some OBIG
locale.setDefault(new Locale(Holders.config.openboxes.locale.defaultLocale ?: "en")) | ||
return locale | ||
} | ||
|
||
static List<Locale> getSupportedLocales() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since locales are static, we could consider caching them in a map (maybe in the LocalizationService) so that we don't need to reconstruct them every time we do a lookup. Currently, every time we call this method we're re-initializing all of the Locale objects. That's not a big deal since it's not really a lot of computation work, but still a good practice IMO.
If we wanted to get really fancy, we could even build that map on app startup based on the locales we have defined in our properties.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is also potentially something that I would move to the separate "further improvements in the supported locale" ticket, but hold until more reviews
@@ -0,0 +1 @@ | |||
default.number.format=\# \# \#, \# \# \#, \# \# \#0.00 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this being used yet?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was an "initial" request from the ticket, so I just added it here to not leave it empty
@@ -69,51 +69,11 @@ class LocalizationService { | |||
*/ | |||
Properties getMessagesProperties(Locale locale) { | |||
Properties messagesProperties = new Properties() | |||
def messagesPropertiesFilename = (locale && locale.language != "en" && locale.language != 'null') ? "messages_${locale.language}.properties" : "messages.properties" | |||
def messagesPropertiesFilename = (locale && locale.language != "en" && locale.language != 'null') ? "messages_${locale.toString()}.properties" : "messages.properties" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in what situations do we want locale.toString()
vs locale.getDisplayName()
? I see we use both
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want to find a message properties file corresponding to the current locale. toString()
concatenates language code with country code together with an underscore (or returns just language code if no country code). So for Spanish, we are getting just es
-> messages_es.properties
and for Mexican Spanish, we will get es_MX
-> messages_es_MX.properties
|
||
def resource = grailsResourceLocator.findResourceForURI('classpath:' + messagesPropertiesFilename) | ||
messagesProperties.load(resource.inputStream) | ||
|
||
return messagesProperties | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I would make sure none adjustments have to be done in the
InitializationInterceptor
, but looking quickly at the code, I think none have to be done.
Locale locale | ||
|
||
if (localeCode?.contains("_")) { | ||
String[] localeCodeParts = localeCode.split("_") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpicky: I'd add the "_"
separator to the Constants.
} | ||
|
||
locale = new Locale(localeCode) | ||
locale.setDefault(new Locale(Holders.config.openboxes.locale.defaultLocale ?: "en")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would move the new Locale(...) ?: "en"
to a separate variable for a better readability.
@@ -1,4 +1,4 @@ | |||
<%@ page import="org.pih.warehouse.core.RoleType" %> | |||
<%@ page import="org.pih.warehouse.LocalizationUtil; org.pih.warehouse.core.RoleType" %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpicky: I know it was done automaticallty, but we used to separate the imports in gsp templates to be one import per line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this is my laziness since I was doing the automatic import and noticed it while creating the PR it's in one line, I'll fix that
grails-app/views/user/create.gsp
Outdated
@@ -1,5 +1,5 @@ | |||
|
|||
<%@ page import="org.pih.warehouse.core.User" %> | |||
<%@ page import="org.pih.warehouse.LocalizationUtil; org.pih.warehouse.core.User" %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
Initially, I was making the changes there too, because I was pulling through this new util every "defaultLocale" as well, but I decided to skip that one for three reasons:
|
@awalkowiak I think even if the users have country-specific language, this should be handled already by the: session?.locale ?: session.user?.locale assuming the session locale would be set correctly (which you've probably done) new Locale(grailsApplication.config.openboxes.locale.defaultLocale ?: "en") but as long as no one has their defaultLocale set to |
} | ||
|
||
locale = new Locale(localeCode) | ||
locale.setDefault(new Locale(Holders.config.openboxes.locale.defaultLocale ?: "en")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to use "en" from the Locale
class instead of hardcoding it.
@jmiranda I am merging this one, but feel free to leave a post-merge review |
"Some" context https://pihemr.atlassian.net/browse/OBPIH-6410?focusedCommentId=153567