Apostrophe: &#039 or '?

Have a translation or something? It goes here. This can mean modules, documentation, or CMSMS itself!
Post Reply
gigicop
Forum Members
Forum Members
Posts: 56
Joined: Thu Jun 23, 2005 5:10 pm
Location: Parma - Italy

Apostrophe: &#039 or '?

Post by gigicop »

Hi,
I'm translating some modules and I would like you to clarify a doubt that I have.
In some strings the apostrophe is written like "&#039" while in other strings the translators used the "'" character.
So far I've used "'" but I'm not sure if this is the right way to write the apostrophe. In fact, some time ago, I translated a xx_XX.php file using "'" for the apostrophe and when I uploaded it my CMSMS crashed.
In some important modules like the admin module, other translators used "'", therefore I suppose it should work fine in all modules, but I'm not sure about it.
Can you help me?
Thanks in advance.
Bye.

Gigi
10010110
Translator
Translator
Posts: 200
Joined: Tue Jan 22, 2008 9:57 am

Re: Apostrophe: &#039 or '?

Post by 10010110 »

I’m late to the party but wanted to give a reply anyway: the problem with the plain apostrophe character is that it is also used to delimit strings in PHP. If you open a xx_XX.php file in a code editor you’ll see string definitions like this:

Code: Select all

$lang['example'] = 'This is the translated string';
You see how the actual string is enclosed in single quotes. Now, if you were to use the single quote/apostrophe character unencoded inside the string it would result in something like this:

Code: Select all

$lang['example'] = 'Hello, it's me!';
the parser would think that the string ends after “it”, and the rest of the string would be seen as invalid PHP code. This is probably the reason why it crashed the program. You can circumvent this not only by using HTML entities but you could also escape the character by writing a backslash in front of it, like so:

Code: Select all

$lang['example'] = 'Hello, it\'s me!';
Now a little more background, please bear with me:

Sometimes strings in these language files are also enclosed in double quotes like so:

Code: Select all

$lang["example"] = "This is the translated string";
In this case it is safe to use the single quote/apostrophe character because it won’t confuse it with the end of the string. (But in this case, using a double quote character unencoded would be problematic.) It’s not entirely clear to me why and when exactly single or double quotes are used; it seems like it depends on the language files sometimes, or how they were created by the original programmer? I guess someone of the dev team would know.

That said, I would advise to use typographic quotes (a.k.a. “smart quotes” or “curly quotes”) in any case. Not only does this prevent possible PHP errors but it also looks better and is the “correct” way of using quotes/apostrophes (at least in regular text). Here is an explanation on how to type these on the keyboard: https://www.lifewire.com/typing-quotes- ... es-1074104 but you can also copy and paste them from https://www.w3.org/wiki/Common_HTML_ent ... typography (or write them as HTML entities, too). And if you have to use straight quotes, e. g. if you want to print actual code as text, then encode them as HTML entities, such as ' (or ') to be on the safe side.
Post Reply

Return to “Translations”