[Solved] Change Language Locale in LO Calc Options

Keyboard macros or custom scripts

[Solved] Change Language Locale in LO Calc Options

Postby Dheeraj » Sun Jun 14, 2020 12:59 pm

I want to change Language Locale to English India in Libreoffice Calc. We can do it by Going to Tools-Options-Languages and then changing the locale to English India Manually. But I want to do this with Macro if Local is not set to English India. I am new to Open Office or Libreoffice Basic Programming. Can anyone help me in doing it? I am unable to find any code for this even after a lot of searching in Google. Any help will be greatly appreciated. Waiting for Anyone to Reply.
Last edited by Hagar Delest on Tue Jun 16, 2020 7:23 pm, edited 2 times in total.
Reason: tagged solved
Openoffice 4.1
Windows 10
Dheeraj
 
Posts: 11
Joined: Sun Jun 14, 2020 12:46 pm

Re: Change Language Locale in LO Calc Option by LO Basic Mac

Postby Villeroy » Sun Jun 14, 2020 2:25 pm

Dheeraj wrote:I want to change Language Locale to English India in Libreoffice Calc.

The options dialog distinguishes between
1) GUI language
2) Locale for numbers including currencies, dates, times etc.
3) Language of human words for spell checking and auto-correct features.

Normally, this is handled through customized configuration in distribution packages rather than macro code.
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
Villeroy
Volunteer
 
Posts: 29914
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Change Language Locale in LO Calc Options by LO Basic Ma

Postby Dheeraj » Sun Jun 14, 2020 2:59 pm

Thanks for Reply Villeroy.....

You said right options Dialog distinguishes language into three: 1. User Interface Language 2. Locale Language 3. Document Language.

Document Language is used for Spell Checking in LibreOffice/OpenOffice. We can easily change Document Language by a simple macro. When I can change the Document Language by Macro, I am pretty sure there will also be a way to change Locale Language by Macro. Macro is mentioned below which changes the Document Language to English India...


Code: Select all   Expand viewCollapse view
Sub ChangeDocumentLanguage
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 ----------------------------------------------------------------------
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Language"
args1(0).Value = "Default_English (India)"

dispatcher.executeDispatch(document, ".uno:LanguageStatus", "", 0, args1())
end sub
Openoffice 4.1
Windows 10
Dheeraj
 
Posts: 11
Joined: Sun Jun 14, 2020 12:46 pm

Re: Change Language Locale in LO Calc Options by LO Basic Ma

Postby Villeroy » Sun Jun 14, 2020 5:33 pm

Code: Select all   Expand viewCollapse view
Function setSetupValue(sNodePath$, sProperty$, val) as Boolean
on error goto exitErr
Dim bReturn as Boolean, xconfig, xAccess
dim aArgs(0) as  Object
dim aPropValue as new  com.sun.star.beans.PropertyValue
   xconfig = CreateUnoService("com.sun.star.configuration.ConfigurationProvider")
   aPropValue.Name = "nodepath"
   aPropValue.Value = sNodePath
   aArgs(0) = aPropValue
   xAccess = xconfig.createInstanceWithArguments("com.sun.star.configuration.ConfigurationUpdateAccess",aArgs())
   xAccess.setPropertyValue(sProperty, val)
   xAccess.commitChanges()
   bReturn = True
exitErr:
   setSetupValue = bReturn
End Function

Code: Select all   Expand viewCollapse view
b = setSetupValue("/org.openoffice.Setup/L10N", "ooSetupSystemLocale","en-IN")
msgbox b ' True if successful


This is what I run sometimes in order to get a German locale with default currency but English date acceptance patterns:
Code: Select all   Expand viewCollapse view
Sub My_SetupValues()
   sn = "/org.openoffice.Setup/L10N"
   pn = Array("ooSetupSystemLocale", "ooSetupCurrency", "DateAcceptancePatterns")
   pv = Array("de-DE", "EUR-de-DE", "D/M/Y;D/M;D/")
   for i = 0 to uBound(pn)   
      b =   setSetupValue(sNodePath:=sn, sProperty:=pn(i), val:=pv(i))
      if not b then print pn(i), pv(i)
   next
end sub


getSetupValue queries a current value:
Code: Select all   Expand viewCollapse view
Function getSetupNode(sNodePath$)
Dim aConfigProvider, oNode, args(0) As new com.sun.star.beans.PropertyValue
   aConfigProvider = createUnoService("com.sun.star.configuration.ConfigurationProvider")
   args(0).Name = "nodepath"
   args(0).Value = sNodePath
   getSetupNode = aConfigProvider.createInstanceWithArguments("com.sun.star.configuration.ConfigurationAccess", args())
End Function

Function getSetupValue(sNodePath$,sProperty$)
Dim oNode
   oNode = getSetupNode(sNodePath)
   getSetupValue = oNode.getbyname(sProperty)
End Function
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
Villeroy
Volunteer
 
Posts: 29914
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Change Language Locale in LO Calc Options by LO Basic Ma

Postby Dheeraj » Sun Jun 14, 2020 8:31 pm

Thanks for Your Reply Villeroy......
Your Function works perfectly fine. It does the Job but it does not get applied in realtime. For Example Applied on Current Open File. In order to do that, I have to first Save the Document, then have to run your function and then have to reload the document to get it applied. I am doing all this with this code. If you can eliminate this reloading or Rewrite my ChangeLocale Macro without using Uno Commands, it will be very beneficial. Reloading of Document take at least 4 to 5 Seconds. Otherwise you have already done a great job which is appreciable.

Code: Select all   Expand viewCollapse view
Sub ChangeLocale
dim document   as object
dim dispatcher as object

document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
Globalscope.BasicLibraries.loadLibrary("Tools")

If GetRegistryKeyContent("org.openoffice.Setup/L10N",FALSE).getByName("ooSetupSystemLocale") = "en-IN" Then
   Msgbox "Locale is already set to English India."
Else
   dispatcher.executeDispatch(document, ".uno:Save", "", 0, Array())
   setSetupValue("/org.openoffice.Setup/L10N", "ooSetupSystemLocale","en-IN")
   dispatcher.executeDispatch(document, ".uno:Reload", "", 0, Array())
   Msgbox "Locale Set to India as well as applied Successfully"
Endif
End Sub

Function setSetupValue(sNodePath$, sProperty$, val) as Boolean
on error goto exitErr
Dim bReturn as Boolean, xconfig, xAccess
dim aArgs(0) as  Object
dim aPropValue as new  com.sun.star.beans.PropertyValue
xconfig = CreateUnoService("com.sun.star.configuration.ConfigurationProvider")
aPropValue.Name = "nodepath"
aPropValue.Value = sNodePath
aArgs(0) = aPropValue
xAccess = xconfig.createInstanceWithArguments("com.sun.star.configuration.ConfigurationUpdateAccess",aArgs())
xAccess.setPropertyValue(sProperty, val)
xAccess.commitChanges()
bReturn = True
exitErr:
setSetupValue = bReturn
End Function
Openoffice 4.1
Windows 10
Dheeraj
 
Posts: 11
Joined: Sun Jun 14, 2020 12:46 pm

Re: Change Language Locale in LO Calc Options by LO Basic Ma

Postby Bidouille » Tue Jun 16, 2020 11:46 am

You can't. Some operations require a restart.

XY problem: what is the goal to change this?
User avatar
Bidouille
Volunteer
 
Posts: 449
Joined: Mon Nov 19, 2007 10:58 am
Location: France

Re: Change Language Locale in LO Calc Options by LO Basic Ma

Postby Dheeraj » Tue Jun 16, 2020 11:57 am

Thanks for Replying Bidouille....
I dont want to Use Uno Commands for Saving and Reloading. I want to do that with API commands but don't know how to do that. If you can share it will be very beneficial. Thanks in advance in hope of reply...
Openoffice 4.1
Windows 10
Dheeraj
 
Posts: 11
Joined: Sun Jun 14, 2020 12:46 pm

Re: Change Language Locale in LO Calc Options by LO Basic Ma

Postby Bidouille » Tue Jun 16, 2020 12:53 pm

Did you read my previous message?
Changing language UI must be complete with restarting.
User avatar
Bidouille
Volunteer
 
Posts: 449
Joined: Mon Nov 19, 2007 10:58 am
Location: France

Re: Change Language Locale in LO Calc Options by LO Basic Ma

Postby Dheeraj » Tue Jun 16, 2020 3:32 pm

Did you read the post title? We are not changing UI Language. We are changing Language Locale and that can changed as well as applied without reloading of Document. Not Waiting for Your Next Comment.
Openoffice 4.1
Windows 10
Dheeraj
 
Posts: 11
Joined: Sun Jun 14, 2020 12:46 pm

Re: Change Language Locale in LO Calc Options by LO Basic Ma

Postby Dheeraj » Tue Jun 16, 2020 4:30 pm

Finally Solved. No Reloading of Document. Language Locale Changed as well as Applied in Realtime. Here is the final Code.

Code: Select all   Expand viewCollapse view
Sub ChangeLocale
Dim Doc as Object

Doc = ThisComponent
Globalscope.BasicLibraries.loadLibrary("Tools")

If GetRegistryKeyContent("org.openoffice.Setup/L10N",FALSE).getByName("ooSetupSystemLocale") = "en-IN" Then
Msgbox "Locale is already set to English India."
Else
If setSetupValue("/org.openoffice.Setup/L10N", "ooSetupSystemLocale","en-IN") = True Then
Doc.calculateall()
Msgbox "Language Locale Set as well as Applied to India Successfully"
Endif
Endif
End Sub

Function setSetupValue(sNodePath$, sProperty$, val) as Boolean
on error goto exitErr
Dim bReturn as Boolean, xconfig, xAccess
dim aArgs(0) as Object
dim aPropValue as new com.sun.star.beans.PropertyValue
xconfig = CreateUnoService("com.sun.star.configuration.ConfigurationProvider")
aPropValue.Name = "nodepath"
aPropValue.Value = sNodePath
aArgs(0) = aPropValue
xAccess = xconfig.createInstanceWithArguments("com.sun.star.configuration.ConfigurationUpdateAccess",aArgs())
xAccess.setPropertyValue(sProperty, val)
xAccess.commitChanges()
bReturn = True
exitErr:
setSetupValue = bReturn
End Function
Openoffice 4.1
Windows 10
Dheeraj
 
Posts: 11
Joined: Sun Jun 14, 2020 12:46 pm


Return to OpenOffice Basic, Python, BeanShell, JavaScript

Who is online

Users browsing this forum: No registered users and 2 guests