Remove Localized Translations

How do you remove all the translations out of a project for a specific language?
I have tried importing a xojo_locale file which has had all the translations removed but the Xojo IDE does not remove them. Seems to only add / update set values.
I’m working on a rather large project with 5700 localized constants and would like to remove some half completed translations.

Other than writing a script to process the xojo_code files with the constants and removing the lines for that language I cannot seem to find i a way to remove them.

I had the same issue for iOS Apps.
Unfortunately there is no easy way to do this.

If your project is a MacOS app I have a xojo build script I can share that will automatically strip out languages.

I have an open feature request for this:

That’s massive! I only have 600 localized constants in my largest app but 37 different languages.

I have about 300 dialogs in there, app has been developed for about 20 years so probably a lot of unused constants. Which is also impossible to figure out which ones they are.

please send me your script

Set up:

Add a module in your project named Language
In that module add Boolean constants named:

  • kRemove_de
  • kRemove_fr
  • kRemove_XX

replace XX with a ISO2 language code.

Add this build script after the Build process. That script will only work if you are working on MacOS.

//Check if a Directory exists
Function DirExists(dirName As String) As Boolean
  Dim cmd As String="[ -d '"+dirName+"'  ]&& echo ""="" || echo ""*"""
  Return cmd="="
End Function

//Check if a file exists
Function FileExists(fileName As String) As Boolean
  Dim cmd As String="test -f '"+fileName+"' && echo ""="" || echo ""*"""
  Return cmd="="
End Function

//Return the list of .lproj dir in the app (localized info)
Function ProjList(dirName As String) As String()
  Dim cmd As String = "find '"+dirName+"' -maxdepth 1 -type d -name ""*.lproj"""
  Dim v() As String=Split(doShellCommand(cmd), Chr(10))
  Return v
End Function

//Get the contents of file (text as UTF16 converted to UTF8)
Function fileContents(path As String) As String
  If fileExists(path) Then
    Dim cmd As String="iconv -f UTF-16 -t UTF8 '"+path+"'"
    Return doShellCommand(cmd)
  End If
End Function

//Search the infoPList related stuff in the local Localizable strings and create the relative InfoPlist file
Sub checkLocalizedPinfo(basePath As String)
  Dim src As String=fileContents(basePath+"/Localizable.strings")
  If src<>"" Then
    Const kprefix As String="""infoPlist."
    Dim v() As String=src.Split(Chr(13))
    Dim z() As String
    For i As Integer=0 To v.LastIndex
      If v(i).Left(kprefix.Len)=kprefix Then z.Add v(i).Replace(kPrefix, """")
    Dim cmd As String="echo '"+Join(z, Chr(13)).ReplaceAll("'", "'""'""'")+"' | iconv -t utf8 > '"+basePath+"/InfoPlist.strings'"
    'Print cmd
    If cmd<>"" Then Print "???"+cmd
  End If
End Sub

Function deleteFolder(path As String) As Boolean
  Dim cmd As String="rm -R """ + path + """"
  'Print("Result :" + cmd)
  Return cmd=""
End Function

//The app source created
Dim fName As String=CurrentBuildLocationNative+"/"+CurrentBuildAppName

//Check the localizations
If dirExists(fName) Then
  Dim v() As String=ProjList(fName)
  'Print("Found " + EndofLine + join(v(), Endofline))
  Dim removedLang() As String
  For i as Integer = 0 to v.ubound
    If len(v(i)) = 0 then continue for i
    Dim lang As String = v(i).mid(fName.len+2).nthfield(".", 1) '.Replace(".lproj", "")
    Dim b As String = ConstantValue("Language.kRemove_" + lang)
    if b = "True" then
      //Needs to be deleted
      //Delete the folder
      if deleteFolder(v(i)) <> True then
        Print("Cannot delete " +  v(i))
        removedLang.append lang
      end if
    end if
  if removedLang.Ubound > -1 then
    Print("Removed languages: " + join(removedLang, ", "))
  End If
End If

Do people keep localisations in their project all of the time?

We found it easier to just import the Lingua files when we wanted to create a build / do some multilingual testing as it avoided issues like this.


I keep all 38 localisations in my app.
But thanks to the script I shared, I can remove Croatian which isn’t completed yet.

I don’t want to import 30+ language files when building. That would take too much time. Also, I regularly switch the language of the app while debugging in order to verify how a new screen looks for each language. That is especially true for the Purchase screen of my app that needs to look perfect in each language.

You can drag and drop all of the Lingua files from the file system into the Xojo Navigator panel. It takes around 2 seconds to import 23 Lingua files containing approx. 2500 strings.

Yeh, we do that as well. Luckily, our auto-flexing control subclasses take care of issues caused by text width differences so we don’t have to spend much time fixing issues but there is the odd occasion where we have to add custom code to handle specific layouts.

1 Like

Removing them at build is a smart idea. I will add this to my build scripts. Thanks.
I just built an app to send off all my translations to open AI to translate for me, you can send the “context” of the app so it knows how to better translate. Then we just send to someone to look over them … all 5700 !