forked from mekomsolutions/openmrs-module-initializer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mekomsolutions#248 - Support setting names and descriptions of metada…
…ta from translations in the context locale
- Loading branch information
Showing
6 changed files
with
107 additions
and
15 deletions.
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 |