@Lupp
Thanks for your contribution, it was most useful. Much appreciated.
I used 'Paragraph' instead of 'Text Range' in the title of the post because I think a user looking for information on this topic is more likely to use 'Paragraph' in his search than 'Text range'. But you are right, those are different things. May be I should have used 'Text range' in the title of the post since that is what I was actually looking for.
When I ask a question on this forum and start receiving help that is completely off target I always promptly mark it SOLVED and thank all the folks who have contributed ideas. My assumption is always that if I am not receiving valuable help it is because my question was stupid, I am too dumb to understand the answers, or both. I don't want to continue bothering the regular 'solvers' of the forum (may them be thanked again for their admirable commitment to help) with a stupid question.
Meanwhile, I have found myself a way to get() / set() the 'Language' attribute of a text range.
Suppose your text range is a paragraph 'portion' that you have obtained by creating an enumeration of a paragraph's 'portions'.
To get its 'Language' :
Code: Select all
msgbox (paraPortion.CharLocale.Language)
REM paraPortion is the variable to which you assign the elements of the enumeration
REM The Language field of the Locale structure is a string, see com.sun.star.lang.locale
You get "en", "fr", "it", "nl" whatever the Language attribute of the range is (Note : the Language attribute of a range has nothing to do with the language in which the text is written)
To set its 'Language' was more difficult.
Code: Select all
paraPortion.CharLocale.Language = "en"
did not work. If the original Language was "fr" it stayed "fr", not "en", after this statement was executed. I still have to understand why this is, suspect other formatting attributes take precedence over the direct formatting of the 'portion' by the macro.
The trick I used is to first define a Character Style that has English as its Language attribute. Call it 'myCharStyleEn'
Then you assign this style to your text range :
Code: Select all
paraPortion.CharStyleName = "myCharStyleEn"
Works like a charm.
Probably not a very elegant, or even fully technically correct, solution, but it gets the job done. I leave it up to the gurus to come up with another one.
[In case you are wondering : I needed to do all this to amend a bunch of files created in MS WORD and then save them as OpenOffice/Writer documents. For some reason, those MS WORD files had some paragraphs where different Language attributes had been used all along (do not ask, I do not know why). I did try to assign to the whole document a Paragraph Style that had English has its Language attribute but that had no effect on the Language attribute of the paragraph portions that had another Language assigned to them.]
Thanks again for your help.