2

I'm using strtr to make translations and since I started using Japanese, it fails to replace placeholders.

Here is an example string:

%service% で入力してください

If I just run the code below, it will not replace %service% placeholder:

strtr("%service% で入力してください", array("%service%" => "Facebook"));

Result: %Service% で入力してください

But if I do it in many other languages, it simply work. Eg: %service% connect becomes Facebook connect

Anyone know a workaround to that?

chris85
  • 23,846
  • 7
  • 34
  • 51
ThyagoTC
  • 33
  • 6

1 Answers1

1

That's because %service% does not equal %service%.

Pay attention to % sign!

chris85
  • 23,846
  • 7
  • 34
  • 51
Dmitriy Troyan
  • 483
  • 7
  • 13
  • 1
    Thanks a lot mate. Looks like the translator replaced our original % by the japanese one %. It was really silly! – ThyagoTC Apr 10 '17 at 18:17
  • 1
    @ThyagoTC You could use a regex to allow for both versions.`/([%%])service\1/u` replace with `Facebook` with `preg_replace`. – chris85 Apr 10 '17 at 18:41
  • 1
    Good idea, I've alerted them to be careful with placeholders, but I better use that to avoid other developer getting stuck in the same problem again. – ThyagoTC Apr 10 '17 at 18:54