UI language changes are not applied until manual restart

Hi all. I use uno api for python and need to change UI language dynamically.

I use the following code:

import uno
local_context = uno.getComponentContext()
resolver = local_context.ServiceManager.createInstanceWithContext(
        "com.sun.star.bridge.UnoUrlResolver", local_context)
remote_context = resolver.resolve(connection_url) #my url here
service_manager = self.remote_context.getServiceManager()
desktop = service_manager.createInstanceWithContext(
        "com.sun.star.frame.Desktop", remote_context)

# set needed UI language
nodepath_prop = uno.createUnoStruct("com.sun.star.beans.PropertyValue")
nodepath_prop.Name = "nodepath"
nodepath_prop.Value = "org.openoffice.Office.Linguistic/General"

enableasync_prop = uno.createUnoStruct(
        "com.sun.star.beans.PropertyValue")
enableasync_prop.Name = "enableasync"
enableasync_prop.Value = True

config = service_manager.createInstanceWithContext(
        "com.sun.star.configuration.ConfigurationProvider",
        remote_context)

current_prop_state = config.createInstanceWithArguments(
        "com.sun.star.configuration.ConfigurationUpdateAccess",
        (nodepath_prop, enableasync_prop))

current_value = current_prop_state.getPropertyValue("UILocale")
if current_value != "ru":
      current_prop_state.replaceByName("UILocale", "ru")
      current_prop_state.commitChanges()
      config.flush()

document = desktop.loadComponentFromURL('private:factory/scalc', '_blank', 0, ())

But when document is open language is still not changed in UI (but changed in options, see screenshot)

How can I force Calc document to use options for UI via python code?

Note: when I restart Libre manually, language is applied correctly

When you change UI language manually, LO asks for instant restart for the change to take effect. There is no reason the underlying function behaves differently in a macro.

@ajlittoz, I agree, but what is restart in terms of macro? How can I do it via script

No idea, I never wrote a macro.

the following macro does something more … saving timestamped copies … but should contain all the building blocks you need, reopening is realised via a shell call, not sure how exact you’ll meet your ‘closing point’, and still a challenge to continue with your macro … have fun …

`sub schliessenoeffnen ' *******************************br 26.09.2019  

Dim oDoc, oForm, oblatt, oDatei as Object 
 
' remember file 
odoc = thiscomponent 
speicherOrt = ConvertFromUrl(odoc.getLocation) 

' strip if timestamped, apply new timestamp, save
extens = Right(speicherort,4)
dateilen = len(speicherort)-4
dateibase = left(speicherort, len(speicherort)-4)
tail = right(dateibase,17)
tlen = Len(Tail)
  pos1 = instr(tail,"_")
  pos2 = instr(tail,"-")
  if pos1 > 0 and pos2 > 0 then
    if pos1+ 5 <> pos2 then 
      notimestamp = true
    else
      if Mid(tail, pos1+ 11,  1) <> "_" or Mid(tail, pos1+ 8, 1) <> "-" or Mid(tail, pos1+ 14, 1) <> "-" then
        notimestamp = true
      else
        dateibase = left(dateibase,len(Dateibase)-tlen) 'strip old timestamp
      end if   
    end if  
      dateibase = dateibase & "_" & Format(Now(),"YYYY-MM-DD") & "_" & format(time(),"HH-MM" 'add new timestamp
  else
    dateibase = dateibase & "_" & Format(Now(),"YYYY-MM-DD") & "_" & format(time(),"HH-MM"
  end if
fname = dateibase & extens
surl = converttourl(fname)
dim dummy()
odoc.storeasurl(surl,dummy())

' Formular schliessen 
oDoc = thisComponent.currentController.frame
oDispatch = createUnoService("com.sun.star.frame.DispatchHelper")
oDispatch.executeDispatch(oDoc, ".uno:CloseDoc", "", 0, Array())

' Formular öffnen 
DIM sDatei, sPfad as string
oDoc = ThisComponent
sDatei = fname

sUrl_1 = ConvertToURL(sDatei) 'Umwandeln URL
sPfad =  "scalc.exe" 'Pfad der zu verwendenden Applkation
Shell(sPfad + " " + sDatei,3) 'nun öffnen der Datei mit dem angegebenen Programm

end sub 'schliessenoeffnen ' *******************************br 26.09.2019