dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #02649
Re: Translate Organisation unit name
Dear Lars and everyone,
Thank you for replying to me on this issue,
But seemly that, my previous mail maybe not clearly to describe the problem
which I want to express to you. So, this is a simple example for this one:
*GENERAL:**
This is the method will be used to convert the input Collection, where
contains one or many TRANSLATION object**(s)*
*
private Map<String, String> convertTranslations( Collection<Translation>
translations )
{
Map<String, String> translationMap = new Hashtable<String, String>();
for ( Translation translation : translations )
{
if ( translation.getProperty() != null && translation.getValue()
!= null )
{
translationMap.put( translation.getProperty(),
translation.getValue() );
}
}
return translationMap;
}*
*CASE NUMBER 1:*
As we knew, the method which is being used in I18nAction.java file is:
*getTranslations( String className, int objectID, Locale locale );*
You can see that this method receives three of arguments. And specially, we
should attend to the second argument. It will present for one corresponding
Translation object.
Or we can understand that the method above which would return only and only
one object that was contained in Map.
It's very easyto check this by the simple query in you DB:
---------------------------------------------------------
*SELECT * FROM TRANSLATION
WHERE objectClass = 'className'
AND objectId = objectID
AND locale = 'locale';
*---------------------------------------------------------
*
**Note: *We could get the result with *one or many row(s)* from this
statement query. BUT it's only *ONE TRANSLATION *object that contains *one
or many properties *(they are: name, shortname, comment, description,
etc...).
*CASE NUMBER 2:*
How about the case that we will use the method as following form:
*getTranslations( String className, Locale locale );*
*
*The method above will return a Collection of None of Duplicated TRANSLATION
objects, also we can check this by the simple query:
*
*---------------------------------------------------------
*SELECT * FROM TRANSLATION
WHERE objectClass = 'className'
AND locale = 'locale'* ;
---------------------------------------------------------
And the problem will occur in this case if we try to use *
convertTranslations(Collection<Translation>)* to convert the specified
Collection to Map<String, String>
More details by checking the example below:
For example, I have got a Collection object which contains 3 Elements (3
Translation objects):
---------------------------------------------------------
---------------------------------------------------------
*Translation A*
name: A
shortname: A
*Translation B*
name: B
shortname: B
comment: "*This is Translation B*"
*Translation: C*
name: C
---------------------------------------------------------
---------------------------------------------------------
And then, using the convertTranslation() method for this Collection. What
will be happened in this case?
Can you guys imagine the result that we will get ???
In my opinion, the result is that:
Map {
* [ name = TranslationC.name, *
* shortname = TranslationB.shortname, *
* comment = TranslationB.comment ]*
}
What are you thinking about the result as presented. Anything's wrong here ?
Thanks for all and expecting your idea/explanation.
*P.S 1*: I copied as quickly paste the description of the put() method of
Map class. Please take around:
===========================================================================
String java.util.Map.put(String key, String value)
put
V <../../java/util/Map.html> *put*(K <../../java/util/Map.html> key,
V <../../java/util/Map.html> value)
Associates the specified value with the specified key in this map (optional
operation). *If the map previously contained a mapping for the key,* *the
old value is replaced by the specified value*. (A map m is said to contain a
mapping for a key k if and only if
m.containsKey(k)<../../java/util/Map.html#containsKey%28java.lang.Object%29>would
return true.)
*Parameters:* key - key with which the specified value is to be associated
value - value to be associated with the specified key
===========================================================================
*P.S 2*: Sorry for a mail is too long !
2009/10/21 Lars Helge Øverland <larshelge@xxxxxxxxx>
>
> Hi Hieu
>
> I see your point and understand what you mean. But after looking at the
> code it seems this is not the cause of the problem. The convertTranslations
> method is used for only one object at the time, meaning that duplicates will
> never occur (since an object does not have properties with the same name).
> Anyway thanks for looking into this :-)
>
> cheers
>
> Lars
>
>
>
--
Hieu.HISPVietnam
Good Health !
Follow ups
References