[Solved] How to change the default language setting in a ...

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
aharnack
Posts: 32
Joined: Mon Jun 02, 2008 8:26 pm

[Solved] How to change the default language setting in a ...

Post by aharnack »

Hi,

I use to write documents in two different languages and have to adopt the language settings accordingly and rather frequently (Tools > Options... > Language Settings > Languages > Default languages for this document (For this document only)). I tried to record this into two macros, but all I got was this (which does nothing):

Code: Select all

sub SetEnglich
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
rem dispatcher.executeDispatch(document, ".uno:OptionsTreeDialog", "", 0, Array())


end sub
I bet I only need to find the right property, but I so far I tried in vain. Does anybody know how to change the default language setting for the document from within a macro?

Thanks,
Andreas

PS: OpenOffice 2.4, Microsoft XP
Last edited by aharnack on Fri Jun 13, 2008 9:10 am, edited 2 times in total.
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: How to change the default language setting in a macro?

Post by Villeroy »

Why not use styles bound to shortcuts? Changing the language through hard formatting has several disadvantages.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
Hagar Delest
Moderator
Posts: 32665
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: How to change the default language setting in a macro?

Post by Hagar Delest »

Before going to a macro, have you read that: [Tutorial] Spell check and Language configuration? Changing the language is not so difficult now. Either a right click to edit the Default paragraph style or Tools>Language>For all text.

Thanks to add '[Solved]' at beginning of your first post title (edit button) if your issue has been fixed.
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
aharnack
Posts: 32
Joined: Mon Jun 02, 2008 8:26 pm

Re: How to change the default language setting in a macro?

Post by aharnack »

Villeroy wrote:Why not use styles bound to shortcuts?
Well, styles are a kind of taken. I use them quite heavily and consequently have a rather significant number of customized styles. Using them to control spell checking as well would imply to maintain many of them twice, once for each language. Besides, I think that in general that approach is wrong. A headline is a headline, no matter in what language the words are. So unless for special cases, were the language is given and unlikely to change (let's say you have a headline style specifically to quote Shakespeare) or spell checking should be turned off completely (like for code examples or keywords), I feel that the document's default language is a much better place to specify it. After all, it works perfectly well, only that I feel it's a bit annoying to set it. (I counted 8 clicks plus a search in a rather long list.)
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: How to change the default language setting in a macro?

Post by Villeroy »

...I feel that the document's default language is a much better place to specify it. After all, it works perfectly well, only that I feel it's a bit annoying to set it. (I counted 8 clicks plus a search in a rather long list.)
You can store copies of the respective template with the respective default language.
Tools>Options...Lang...Western default language for new documents plus "For current document only". Then File>Templates>Save... [myTemplate_enGB]
Anyway,
ThisComponent.CharLocale is a locale struct.

Code: Select all

Dim loc as new com.sun.star.lang.Locale
loc.Language = "en"
loc.Country = "US"
ThisComponent.CharLocale = loc
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
aharnack
Posts: 32
Joined: Mon Jun 02, 2008 8:26 pm

Re: How to change the default language setting in a macro?

Post by aharnack »

Villeroy wrote: Anyway,
ThisComponent.CharLocale is a locale struct.

Code: Select all

Dim loc as new com.sun.star.lang.Locale
loc.Language = "en"
loc.Country = "US"
ThisComponent.CharLocale = loc
That looks great.

Thanks,
Andreas
Post Reply