Skip to main content
November 6, 2010
Answered

Cross Platform: How to put an ampersand into TranslatedStrings

  • November 6, 2010
  • 2 replies
  • 892 views

I want to show the string "B & W" as a title.

If I put "B & W" into my TranslatedStrings, I get

Windows: "B  W"

Mac: "B & W"

If I put "B && W" into my TranslatedStrings, I get

Windows: "B & W"

Mac: "B && W"

If I use the unicode for ampersand nothing changes. Do I have to use different zStrings for different Platforms? Or should I wrap the LOC function with custom code and always put "&&" into my TranslatedStrings?

Correct answer johnrellis

The only workaround I've found is to substitute "&&" for "&" at runtime using this idiom:

    WIN_ENV and s:gsub ("&", "&&") or s

I've had to do that with static_text.title.

2 replies

Legend
October 6, 2025

@johnrellis 

 

I realise that this is a very old post, but the problem with && in text strings on Windows has just reared its ugly head in a plug-in I'm developing.

 

Although I can use this  ( WIN_ENV and "&&" or "&" ), it is a big problem when a string is part of a popup control.

 

I will give an example to make myself clear tomorrow. Put simply, in Windows using B&W in a normal text string works fine, but when it is an item in a popup list, B&W is displayed in the list as BW.

 

johnrellis
johnrellisCorrect answer
Legend
November 6, 2010

The only workaround I've found is to substitute "&&" for "&" at runtime using this idiom:

    WIN_ENV and s:gsub ("&", "&&") or s

I've had to do that with static_text.title.

November 6, 2010

A implemented something similiar. For me it is saver to use the opposite: if MAC_ENV then substitute && by &.

This is, because I reuse some of lightroom's default TranslatedStrings that use "&" to define hot keys. Your solution would show me unwanted chars in Windows.

areohbee
Legend
November 6, 2010

I added the content of this thread as a "Pearl of Wisdom" at assembla/lrdevplugin, and updated the base classes accordingly (not yet released).