Language translation

I have looked for an answer to my question, but it doesn’t appear that it’s been covered. I have a program written in English. Everything runs fine. I’d like to change the text and labels from English to Spanish to broaden the program customer base.

Has anyone done this? I have found using an English to Spanish translating program to be questionable as it appears one word can have multiple meanings and there is no way for me to be sure I’m not offending by using the word in the wrong context.

I’d appreciate some guidance on this if you’ve done this and you have the time to comment. Thank you in advance.

Jim Backus

1 Like

Start by converting all your text into constants. All the text that users can see moved into contents. There is a switch on the constant editor that said Localized. If you turn that on then you can add Platform and Language specific versions of each of these contents. Xojo will then show the appropriate language for the system you are on.

To use a constant in the UI place a # before the name of the constant. For example if you have a button that says OK. Make a constant called kButton_OK, put a default value of OK in it. Add a spanish version (in the panel on the left). In the button caption box place #kButton_OK. The IDE will show the OK for you.

You will see you can have Spanish, Italian etc all in a single constant. They sky’s the limit.

2 Likes

1.Use localized constants rather than hardcoded strings when you want those strings to appear in different languages.

2.Find someone who understands English, Spanish and your application to perform the translation or use DeepL / Google Translate and hope for the best.

You might also have to deal with other issues such as your UI not leaving enough space to display localised text when it is longer.

1 Like

Check out “OpenLingua with Deepl” at Xojo + Alfred . Export your localisable strings to a file. This can be read by OpenLingua and then automatically translated if you have a Deepl API key. The translations aren’t that bad. I even can add dictionary items so that certain words are translated correctly. The result I export to csv and send that to volunteers from my users.

1 Like

Thank you Ian, Kevin and Beatrix. I appreciate the responses. Hadn’t thought that a language other than English might require a longer phrase.

The next question seems to be is the world English oriented enough that the majority of people would accept English as the primary and possibly only language alternative? Agin, thank you.

You would have to do some research in your market to determine if English-only would be acceptable.

For reference, our software is in English + 23 other languages.

No. But it really depends on your audience. I have many older users and their English is not that good. My German users like the German website and support. And the French prefer French always.

I appreciate the added guidance. Thank you.

When it comes to allocating enough space in your UI for translated (localized) text, I start with French, Spanish, German and Italian. They appear to have some of the longest phrases after translation from English.

I also use https://www.bing.com/translator as it’s free and appears to understand the nuances of English fairly well (mostly). You can only do a single text translation at a time, but I just do them as I go, for each new added localized Constant. They also have an API (with a free tier), if you want to automate the task more.

Here’s a relatively recent article that compares Microsoft’s translation service against Google’s. The conclusion appears to mimic my own findings.

The IDE will allow you to set a language and look at your dialogs with that language in place. You can then adjust the spacing, without guessing. Change to another language and check that. In extreme circumstances I’ve made the odd button check the text width and increase a single button size when required.

I’ve also made changes to the interface in a few places, for example using a PopupMenu rather than RadioButtons and to be honest it made the dialog better as I was able to be more explicit even in English. It just ended up working better in English that way. Doing the other languages made me think about it more.

1 Like

There used to exist an API worth mentioning, but I can’t find it right now. It was named GetBestControlRect, IIRC, and would automatically get the best bounds for the given caption.
Wondering what happened to it (or nothing) :man_shrugging:.

You can calculate the width required for a given string as follows:

Var Image As New Picture( 100, 100 ) // If you are using a non-standard font assign the font name and size / bold / italic etc.
Var LabelWidth As Integer = Image.Graphics.TextWidth( "Some text" )

Obviously it doesn’t take into account anything to do with RadioButton circles spacing etc, just the labels.

There’s a “GetBestControlRect” function in Carbon API. It only works with Carbon controls and Xojo macOS has been using Cocoa controls for a long time.

1 Like

Thanks. So I assume there’s no Cocoa replacement for this function.

Not that I can see. There’s one that says go to smallest possible size (intrinsic size). There’s another that seems to lean toward getting a size, but it also seems to want a size provided as a parameter. Not sure why. Others will likely know better than me.

Thanks; we’ve come to the same conclusion. That’s too bad: this API proved to be useful. Wondering why it has been abandoned.

Likely because they have intrinsic size (the smallest a control can be for a given language and display size) and a constraints system. The same one that Xojo supports for iOS, is also built into macOS (just not supported by Xojo).

Good point. Constraints were probably not existing in Carbon.

Indeed