-
Notifications
You must be signed in to change notification settings - Fork 80
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
[#248] Support for loading-time L10n of metadata names and descriptions based on Context's locale. #249
Open
mseaton
wants to merge
1
commit into
mekomsolutions:main
Choose a base branch
from
mseaton:ISSUE-248
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[#248] Support for loading-time L10n of metadata names and descriptions based on Context's locale. #249
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
api/src/main/java/org/openmrs/module/initializer/api/BaseMetadataLineProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.openmrs.module.initializer.api; | ||
|
||
import org.openmrs.OpenmrsMetadata; | ||
import org.openmrs.messagesource.MessageSourceService; | ||
|
||
/** | ||
* Extends the BaseLineProcessor by adding methods to retrieve name and description based | ||
* on the configured name and description and translations of these if appropriate. | ||
*/ | ||
public abstract class BaseMetadataLineProcessor<T extends OpenmrsMetadata> extends BaseLineProcessor<T> { | ||
|
||
public static final String TRANSLATE = "_translate_"; | ||
|
||
protected MessageSourceService messageSourceService; | ||
|
||
public BaseMetadataLineProcessor(MessageSourceService messageSourceService) { | ||
super(); | ||
this.messageSourceService = messageSourceService; | ||
} | ||
|
||
/** | ||
* @return the name defined in the current line, which can indicate if it should come from a message | ||
* code | ||
*/ | ||
public String getName(T metadata, CsvLine line) { | ||
String name = line.getName(true); | ||
if (TRANSLATE.equals(name)) { | ||
String code = "ui.i18n." + metadata.getClass().getSimpleName() + ".name." + metadata.getUuid(); | ||
name = messageSourceService.getMessage(code); | ||
} | ||
return name; | ||
} | ||
|
||
/** | ||
* @return the description defined in the current line, which can indicate if it should come from a | ||
* message code | ||
*/ | ||
public String getDescription(T metadata, CsvLine line) { | ||
String description = line.get(HEADER_DESC); | ||
if (TRANSLATE.equals(description)) { | ||
String code = "ui.i18n." + metadata.getClass().getSimpleName() + ".description." + metadata.getUuid(); | ||
description = messageSourceService.getMessage(code); | ||
} | ||
return description; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 9 additions & 7 deletions
16
api/src/test/resources/testAppDataDir/configuration/encountertypes/encountertypes.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
Uuid,Void/Retire,Name,Description,View privilege,Edit privilege,display:en,display:km_KH,_order:1000 | ||
,,Triage Encounter,An encounter for triaging patients.,,,Triage Encounter (translated),ទ្រីយ៉ាហ្គេនស៊ើរ, | ||
aaa1a367-3047-4833-af27-b30e2dac9028,,Medical History Encounter,An interview about the patient medical history.,,,Medical History Encounter (translated),ប្រវត្តិសាស្រ្តវេជ្ជសាស្រ្ត, | ||
439559c2-a3a4-4a25-b4b2-1a0299e287ee,,X-ray Encounter,An encounter during wich X-rays are performed on the patient.,Can: View X-ray encounter,Can: Edit X-ray encounter,,, | ||
400d7e07-6de6-40ac-8611-dcce12408e71,,Foo Encounter,An foo encounter that should not be created.,Can: View foo encounter,,,, | ||
bed6f0f6-ab07-481f-929f-3d26e6cb1138,TRUE,,,,,,, | ||
,,Oncology Encounter,A new description for the oncology encounter.,Can: View oncology encounter,,,, | ||
Uuid,Void/Retire,Name,Description,View privilege,Edit privilege,display:en,display:km_KH,_order:1000,display:fr | ||
,,Triage Encounter,An encounter for triaging patients.,,,Triage Encounter (translated),ទ្រីយ៉ាហ្គេនស៊ើរ,, | ||
aaa1a367-3047-4833-af27-b30e2dac9028,,Medical History Encounter,An interview about the patient medical history.,,,Medical History Encounter (translated),ប្រវត្តិសាស្រ្តវេជ្ជសាស្រ្ត,, | ||
439559c2-a3a4-4a25-b4b2-1a0299e287ee,,X-ray Encounter,An encounter during wich X-rays are performed on the patient.,Can: View X-ray encounter,Can: Edit X-ray encounter,,,, | ||
400d7e07-6de6-40ac-8611-dcce12408e71,,Foo Encounter,An foo encounter that should not be created.,Can: View foo encounter,,,,, | ||
bed6f0f6-ab07-481f-929f-3d26e6cb1138,TRUE,,,,,,,, | ||
,,Oncology Encounter,A new description for the oncology encounter.,Can: View oncology encounter,,,,, | ||
e9be7307-6395-11ee-a0a0-0242ac120002,,_translate_,_translate_,,,,,, | ||
d9fe17f4-639c-11ee-a0a0-0242ac120002,,_translate_,,,,English display,,,French display |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
api/src/test/resources/testAppDataDir/configuration/messageproperties/metadata_fr.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
metadata.healthcenter=Clinique | ||
metadata.healthcenter.description=Ceci est la description d'une clinique. | ||
metadata.healthcenter.description.named=Ceci est la description de la clinique {0}. | ||
greeting=Bonjour from Iniz | ||
greeting=Bonjour from Iniz | ||
ui.i18n.EncounterType.name.e9be7307-6395-11ee-a0a0-0242ac120002=French Encounter Type Name | ||
ui.i18n.EncounterType.description.e9be7307-6395-11ee-a0a0-0242ac120002=French Encounter Type Description |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What locale is going to be used here? My question is at a functional level, OpenMRS' default locale I would assume?
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.
Based on the functioning of the unit tests, it is whatever is returned from Context.getLocale(), which will end up as LocaleUtility.getDefaultLocale(). This will ultimately be whatever is in the GP named "default_locale", and if this is either unset or can't be retrieved, will fall back to "en_GB"
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.
Does that describe the feature appropriately:
?
It would need to be documented well of course, but is that functional intent?
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.
Yes, but it raises a good point. We might want to change this and also be more explicit in the code. Because if someone were to decide to re-run an initializer load themselves (eg. we have an admin feature to allow this for development), then this will pick up their locale, rather than a standard system locale. So maybe the translation here should explicitly pass in the locale that is returned from LocaleUtility.getDefaultLocale(), so that this will always behave consistently in the same system. Then, the documentation can describe this as "...based on the system default locale (default_locale global property)" or something.
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.
@mseaton we all left this PR and thread hanging, what's your take? Should we resume reviewing it, or should be close it for now?