Hi all,
for a selection list in a GUI dialogue, I need to figure out the following three things:
1. All languages known to OpenOffice (i.e. all installed locales).
2. All languages, for which a spell checker is available.
3. All languages used in the current document.
For these three problems I found the following three solutions:
All return values are arrays of type com.sun.star.lang.Locale, which, in turn, is a structure with the following components (https://www.openoffice.org/api/docs/com ... ocale.html):
To display the results in the GUI, I need to convert them to a display name. For that, I found the following function:
This returns a structure com.sun.star.i18n.LanguageCountryInfo, with the following components (http://www.help.openoffice.org/api/docs ... yInfo.html):
The Name entries in there are almost what I need, except that they always contain the default English names. This would not be a problem if the last function (ThisComponent.getDocumentLanguages(1,999)) would not – for some strange reason and against the specification – already perform this transformation, and return a display name instead of the ISO language codes.
However, it returns localised names, i.e. instead of 'English (United States)' or 'German (Germany)' I get something like 'Englisch (USA)' and 'Deutsch (Deutschland)'. While this is actually preferable for the GUI, I need to convert the display name back to ISO codes once the user has made their selection, and the only solution I have come up with so far is to iterate through all available locales, generate the display name and compare it to the selection, which will obviously fail if the compared display names are in different languages.
So here are the questions: Is there a way to tailor the function to obey the GUI's locale settings and return localised names, or is there an alternative way to convert locales to localised display names, or is there an alternative way to find all the languages used in the current document?
Thanks, and best regards,
ah8
for a selection list in a GUI dialogue, I need to figure out the following three things:
1. All languages known to OpenOffice (i.e. all installed locales).
2. All languages, for which a spell checker is available.
3. All languages used in the current document.
For these three problems I found the following three solutions:
Code:
' All languages known to OpenOffice (i.e. all installed locales)aLocales = createUnoService("com.sun.star.i18n.LocaleData").getAllInstalledLocaleNames()' All languages, for which a spell checker is availableaLocales = createUnoService("com.sun.star.linguistic2.LinguServiceManager").SpellChecker.Locales' All languages used in the current documentaLocales = ThisComponent.getDocumentLanguages(1,999) '1: only return Western languages, 999: an arbitrarily chosen maxCount parameter
Code:
Language specifies an ISO Language Code. Country specifies an ISO Country Code. Variant contains a variant of the locale; codes are vendor and browser-specific.
Code:
createUnoService("com.sun.star.i18n.LocaleData").getLanguageCountryInfo(aLocales(i))
Code:
Language ISO-639 language code, for example, "en" or "de" LanguageDefaultName Descriptive language name, for example, "English" or "German" Country ISO-3166 country code, for example, "US" or "DE" CountryDefaultName Descriptive country name, for example, "United States" or "Germany" Variant A variant name
However, it returns localised names, i.e. instead of 'English (United States)' or 'German (Germany)' I get something like 'Englisch (USA)' and 'Deutsch (Deutschland)'. While this is actually preferable for the GUI, I need to convert the display name back to ISO codes once the user has made their selection, and the only solution I have come up with so far is to iterate through all available locales, generate the display name and compare it to the selection, which will obviously fail if the compared display names are in different languages.
So here are the questions: Is there a way to tailor the function to obey the GUI's locale settings and return localised names, or is there an alternative way to convert locales to localised display names, or is there an alternative way to find all the languages used in the current document?
Thanks, and best regards,
ah8
Statistics: Posted by ah8 — Thu Jul 04, 2024 10:55 am