Welcome Guest, Not a member yet? Register   Sign In
language versus html markup?
#1

I'm working on a site that will be delivered in at least English and Spanish (and possibly French, German et. al). I've reached a bit of a conundrum when it comes to displaying in-language prompts that are fairly extensive -- especially when I want to a) merge db data into the text and b) when I want to use HTML markup.

For example, at registration I want to send a welcome-to-our-site email that has HTML markup. In English, this email is likely to look something like this:
Code:
<p><b>Welcome to SiteX</b><.p>
<p>Dear <?php echo $username; ?>,</p>
<p>We are proud to welcome you to our awesome new website blah blah blah blah blah amazing features blah blah blah.</p>
<p>If you ever want to change your preferences please visit <a href="<?php echo $preference_url; ?>">The Preferences Control Panel</a>.</p>

This is obviously in English but I will want one in Spanish too. My instinct would be to create a separate view for the Spanish version of this file, but view loading is not language-aware like the language files are. If I were to do this in some CodeIgniter-orthodox way using language files, I might need to load each paragraph separate from a language file and merge $username and $preference_url into the resulting in-language strings and then merge this, in turn, into my view which would probably be JUST HTML markup like this:
Code:
<p><b><?php echo $welcome_message; ?></b><.p>
<p><?php echo $username_salutation; ?></p>
<p><?php echo $paragraph_1; ?></p>
<p><?php echo $paragraph_2a; ?><a href="<?php echo $preference_url; ?>"><?php echo $paragraph_2b; ?></a>.</p>
Or something like that. Notice how crazy that last line gets if we avoid HTML markup in our language strings.

Does anyone have a way of handling language localization+html markup+merged data all at the same time?
Reply
#2

Multilanguage Database Design in MySQL
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

If I'm not mistaken, that thread recommends that I put all my prompts into my database and the issue of mingling HTML markup with in-language prompts is not even addressed at all.
Reply
#4

You want to mix translations and HTML? I don't see the point of doing that.

You shouldn't use more then one view.
Reply
#5

(10-14-2016, 03:05 PM)Ivo Miranda Wrote: You want to mix translations and HTML? I don't see the point of doing that.
Seems painfully obvious to me that if you want to use HTML markup to render your site and you want it to exist in more than one language, then you are going to need to mix translation and markup.

(10-14-2016, 03:05 PM)Ivo Miranda Wrote: You shouldn't use more then one view.
Not sure what you mean by this.
Reply
#6

What is the problem of using code igniter library for translations?
http://www.codeigniter.com/userguide3/li...guage.html

I still don't get what a translation has to do with HTML. If you need 3 translated strings for a HTML tag then you need them... what other option do you have? Unless you want the guy that is translating stuff to write HTML directly which is strange... but then again it's a string as well
Reply
#7

I think we both agree that we do not want to see any HTML markup in the language string files supported by CodeIgniter.

If you look at the example I gave in my original post and think about it, I think you'll see what I mean.
Code:
<p><b>Welcome to SiteX</b><.p>
<p>Dear <?php echo $username; ?>,</p>
<p>We are proud to welcome you to our awesome new website blah blah blah blah blah amazing features blah blah blah.</p>
<p>If you ever want to change your preferences please visit <a href="<?php echo $preference_url; ?>">The Preferences Control Panel</a>.</p>

To use the built in CI language functionality without any HTML tags in your strings means that translating this view (which is all in English) to Spanish is a pain in the ass. Look at my second example in the original post to see what I mean.
Reply
#8

(This post was last modified: 10-15-2016, 03:51 AM by Ivo Miranda.)

Translations are always a pain. In my opinion translations should only be about strings. But anyways let's assume you want to mix translations and html together. Can you give us an example of what you want to achieve in english and in spanish for example? Output, view and if the vars come from files or db. One line example is enough.
Reply
#9

(This post was last modified: 10-15-2016, 04:31 AM by PaulD. Edit Reason: Added PS )

I think I agree with IvoMiranda.

Definitely only one view. So your new user email view is one file, using multiple language files.

Definitely no HTML in language files. Language files should be strings only.

Design implications. When designing for multiple languages you should take into account the fact that language will be addressed in strings. So for instance your last line should be something like this:

Code:
Orig:
<p>If you ever want to change your preferences please visit <a href="<?php echo $preference_url; ?>">The Preferences Control Panel</a>.</p>

New:
<p>You can change your preferences at any time by visiting your preference control panel.</p>
<a href="mydomain/preference_panel">Preference Control Panel</a>

So with language strings:
<p><?php echo $paragraph_2a; ?></p>
<a href="mydomain/preference_panel"><?php echo $preference_panel_btn; ?></a>

Here I am assuming you are not putting your language setting into your urls. I think this is a bad idea. Even if you are, then yes, you have to put up with having to also constructi the relevant language part of the url and inserting that in the relevant place.

So for an easily translatable page, try to design it so that you are chunking the language into easily translatable language blocks, and with URL's that can be set with just the btn name language string, ie, so url's are independent of language setting. Now when you add german say, you send your language file off to the translator, and when it comes back you add it to the language file and the language code to your languages table, and you are away. Imagine if to add a language you had to create hundreds of new views, altering controllers, as well as implementing html encoding etc etc. What a nightmare that would be for a sizeable site.

PS You should also always default to the default language (usually English) if a language element is missing. Not throw an error.
Reply
#10

Especially for emails I have used special parsing with translations, here is the body only (not full HTML) of a password-recovery message with translations:

Code:
<p>
    <i18n replacement="{{username}}">start_with_hello</i18n>
    <br />
    <br />
    <i18n>reset_password_request_received</i18n>
    <br />
    <br />
    <i18n>reset_password_instructions</i18n>
    <br />
    <a href="{{password_reset_url}}">{{password_reset_url}}</a>
</p>

First I applied Mustache parser, second I applied a parser that uses $this->lang->line() for translating the i18n tags. The idea was from here: https://devzone.zend.com/1441/zend-frame...anslation/

This is an exotic way, probably not interesting for you.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB