[Solved] Change Language Locale in LO Calc Options
[Solved] Change Language Locale in LO Calc Options
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
Reason: tagged solved
Openoffice 4.1
Windows 10
Windows 10
Re: Change Language Locale in LO Calc Option by LO Basic Mac
The options dialog distinguishes betweenDheeraj wrote:I want to change Language Locale to English India in Libreoffice Calc.
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
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: Change Language Locale in LO Calc Options by LO Basic Ma
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...
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
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
Windows 10
Re: Change Language Locale in LO Calc Options by LO Basic Ma
Code: Select all
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
b = setSetupValue("/org.openoffice.Setup/L10N", "ooSetupSystemLocale","en-IN")
msgbox b ' True if successful
Code: Select all
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
Code: Select all
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
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: Change Language Locale in LO Calc Options by LO Basic Ma
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.
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
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
Windows 10
Re: Change Language Locale in LO Calc Options by LO Basic Ma
You can't. Some operations require a restart.
XY problem: what is the goal to change this?
XY problem: what is the goal to change this?
Co-admin french forum branch
Re: Change Language Locale in LO Calc Options by LO Basic Ma
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...
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
Windows 10
Re: Change Language Locale in LO Calc Options by LO Basic Ma
Did you read my previous message?
Changing language UI must be complete with restarting.
Changing language UI must be complete with restarting.
Co-admin french forum branch
Re: Change Language Locale in LO Calc Options by LO Basic Ma
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
Windows 10
Re: Change Language Locale in LO Calc Options by LO Basic Ma
Finally Solved. No Reloading of Document. Language Locale Changed as well as Applied in Realtime. Here is the final Code.
Code: Select all
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
Windows 10