2

Lately, I've been going wild about locales and outputting the correct date/time formats, number formats, money sum formats, percentage signs, etc. for each locale/language combination. Instead of figuring out and hardcoding this myself, which would have taken me hundreds of years, I use PHP's built-in classes such as NumberFormatter: https://www.php.net/NumberFormatter and some of the rest of the classes in the right list on that page.

However, then I got thinking about quotation marks and how I have always known that they differ greatly between languages and regions. I therefore searched all around the classes and online, but oddly found nothing related to outputting quotes.

So, have they simply left this out? Or have I just not found it? If you skim this Wikipedia article, you will see how many different quotation marks/styles there are: https://en.wikipedia.org/wiki/Quotation_mark

Just like my applications now outputs "everything" else properly depending on the locale, I now wish to also be able to output quotes in the correct manner. It's no longer good enough for me to just use the standard English style:

"This is a quote: 'And this is a nested quote.'"

I will be using the above style internally, for the actual "content strings" stored in the database, but when I actually output it for a given locale, I want it to become (for example, for Germany/German):

‚This is a quote: „And this is a nested quote.“‘

Essentially, I want something like (this is made up, based on the syntax used for NumberFormatter):

$a = new QuoteFormatter( 'de_DE', QuoteFormatter::MOSTCOMMON );
echo $a>format('"This is a quote: \'And this is a nested quote.\'"');

And it would output (since Germany/German was specified):

‚This is a quote: „And this is a nested quote.“‘

Please tell me that such a thing exists somewhere in the mysterious, ancient scrolls of the PHP manual and I just haven't been able to find it! Many times before, I have found features in PHP which have existed for 15-20 years and which I never had an idea were in there, and would've saved me an insane amount of headaches...

  • 3
    Quotation marks should always be part of text. If that text is in English, it should use English quotation marks. If it’s in German, it should use German quotation marks. It makes little sense to localize the quotes separately from the text they’re contained in. The quotes should be localized as part of localizing the sentence they’re a part of, using your regular gettext i18n mechanism. – deceze Feb 03 '20 at 06:51
  • @deceze I didn't understand the last part of your message, but the thing is, the content is written in English and then I create separate "versions" for different locales. Since the numbers and all the other stuff I mentioned in my question is localized, I also want the quotes to be localized. Thus, it does make sense, no? –  Feb 03 '20 at 07:31
  • You usually localise for an *audience*. If your audience is English-speaking, you make your text English with English quotes and English time formats and English number formats and all the rest. If your audience is German-speaking, you make the text German with German-style quotes and German time formats etc. I'm not quite sure why you'd want English text but with German-style quotes and German time formats and so on. What *audience* is that addressing exactly? English-speaking Germans? Those Germans would then also be accustomed to English quotes and would in fact expect them in English text. – deceze Feb 03 '20 at 08:13
  • One problem that can occur with overeagerly localising numbers and such but not text is that I'll be unsure whether the number "1,234" means *one thousand two hundred thirty four*, or *one point two three four*. Is that using German number formatting just for me in English text, or is that English text with English numbers? Mixing quotes like this would be similarly weird, albeit perhaps not quite as confusing. – deceze Feb 03 '20 at 08:23
  • 1
    @deceze The whole concept of a "locale" includes a combination of both a language and geographical area. All of the things I've mentioned are highly dependent on both of these. What you say makes no sense unless you equal a locale with just the language, or believe that every geographical area has its own language, and only one, with identical conventions. None of this is true whatsoever. I frankly don't understand why you'd reply with that. –  Feb 03 '20 at 08:26
  • @deceze There would be no such confusion since I use the "en_DE" locale, which means "English in Germany". –  Feb 03 '20 at 08:27
  • 1
    That's why I defined it as *audience*, not geographical area or language. I do in fact prefer en_DE locales myself, since most of the text I consume is English, and I especially want the OS to be in the "original" English; but I prefer German date formats and am surrounded by German currency formatting etc. However, I do not expect nor prefer German style quotes in English text, that makes little sense to me, and I can't remember ever seeing that. Hence: if you localise the text via translation, then you localise the quotes with it. Otherwise, you typically don't. – deceze Feb 03 '20 at 08:37
  • @deceze Making quotation marks "always part of the text" may not always be ideal. If a Browser, search tool, or anything wants to display text that isn't an error-message string (most text isn't), it should be able to localize in one step, not send the data out to be rewritten by someone. Say you're displaying a story to a UK vs. US user. It seems reasonable to localize the qmarks. Likewise for a snippet where you just want to show boundaries clearly, whether the snippet is the user's language, some other natural language, or no natural language (say, a bit of code). – TextGeek Sep 29 '21 at 18:11

0 Answers0