I18n is hard



  • So we're trying to setup this site using Wordpress (strike 1). And because there are two languages why not use this commercial plugin Wpml (strike 2)? And why not use a fairly common templating system, Twig? Strike 3! Automatic :wtf: achieved!

    Turns out Wpml does not know about twig. As in, it doesn't extract translation strings from twig files. That, in itself, is not the WTF. But would you consider the solution proposed by Wpml support staff?

    function translate($key) {  
          static $strings=null; 
         if($strings==null) {
              $strings = array(
                 'string001' => __('String 001', 'domain'), 
                'string002' => __('String 002', 'domain'), 
                'string003' => __('String 003', 'domain'), 
                'string004' => __('String 004', 'domain'), ... );
          }
        return isset($strings[$key])?$strings[$key]:''; 
    } 
    
    In the template:
    
    {{ wp.translate('string003') }}  
    

    I mean, why not just admit "Sorry we do not support twig templates at this moment." Nooo, let's propose this ugly hack. Oooh and what if that's too complicated? We've got you covered:

    {% if wpml_current_lang == 'es' %}
    Spain
    {% elseif wpml_current_lang == 'ca' %}
    Català
    {% else %}
    Other
    {% endif %}
    


  • @gleemonk said:

    So we're trying to setup this site using Wordpress. Automatic :wtf: achieved!

    FTFY



  • We do not have the same standards. I envy you.



  • Wordpress is like the goatse of web security. Do not want.



  • Yeah I wonder what will come of it. In the past I've had the pleasure to try and explain to irate customers that, based on our understanding, we must assume that their site was destroyed (all images deleted) or infected (malware links on the home page) by a breach on another site that used the same shared :wtf: hosting.

    I suppose I'll have to get used to the idea that the breaches are happening to our customer now.



  • Do you have any sway over them to convince them to switch to a cheap-as-hell dedicated VPS (from, say, Digital Ocean or Amazon EC2)?! Doubt it's more than their shared hosting...may be even less, and far more secure (depending on configuration).



  • I've done template extraction in previous and current job and each time I had to write some glue for the project to make things work.

    My weapon of choice would be gettext for extracting from code and translate toolkit for any additional glue I needed to write and weblate for managing the translations.

    For web I'd start with English¹ templates, run them through the translate toolkit's html2po extractor and then generate translated templates back with po2html. Preferably just having copy of the templates for each language, but if I couldn't do that (I don't know wordpress) I'd just combine them with the {% if wpml_current_lang… hack. Generated ugliness does not bother me.

    The main advantage of this approach is that you can tweak the master templates until you are satisfied and then run the extractor and it will tell you what needs to be translated, which is where all the $strings = array(… hacks and manually maintained {% if… hacks fail miserably.


    ¹ Our native language is not English, but we still do the master templates in English and not our native language. The reason is that if something is not translated, the toolchain will leave the bit from the master template in and showing the user a bit of English less of a problem than showing them a bit of some little known language. So if your audience predominantly knows some specific language, using that as master language is fine. For global audience, English is preferred.



  • I hate gettext. It's the most convoluted way of handling translations. Ugh! Another technology that should die in the fires of purification.



  • @rc4 said:

    Do you have any sway over them to convince them to switch

    We did manage to convince them to switch to a provider with a clue, yes 😄 It wasn't that hard:

    Here's the bill for (incompletely) restoring your site. We recommend you switch to Hosting With Clue which we could do for you at about the same price the restore cost you. Also they have backups. Bear in mind that we must assume what happened to your site could happen again at any minute.

    Edit: I wouldn't want to have them on a VPS because they are not qualified to look after it. Paying a hosting provider to keep a website up is a lot cheaper than paying somebody to look after your VPS. We have one customer who opted for a managed VPS. They pay ten times more and get worse service. "Yeah your site is down. We turned it off because it generated a lot of traffic. We didn't bother to look what it was."



  • @Bulb said:

    and then generate translated templates back with po2html. Preferably just having copy of the templates for each language

    That seems like an ingenious hack. I do not have a problem with compiled templates. Generating a copy per language seems like no big deal. On the other hand we'd prefer allowing our customers to adjust translations from within Wordpress. We promise dynamic websites after all.

    @Eldelshell said:

    I hate gettext.

    At its base you probably hate the innate complexities of translating. Not to detract from your justified anger towards gettext of course 😃



  • What do you suggest instead?

    To be viable replacement, it must take care of detecting changes in the master copy that are not yet translated and must not expect translators to understand much technical details. And of course if you hate gettext, it probably shouldn't be the same thing in pale blue (like e.g. the tool built into Qt).



  • @gleemonk said:

    On the other hand we'd prefer allowing our customers to adjust translations from within Wordpress. We promise dynamic websites after all.

    The html2po/po2html means translators see the text split to phrases and paragraphs. That is a way to ensure that all translations contain the same information and that only the parts that get changed need to be translated, but it means the translated templates can't be edited as whole.

    However if you install weblate or pootle alongside, you could write a couple of scripts that would automatically extract strings from master templates when they are edited or upon some request in the management interface and then automatically regenerate the translated templates when the translations are updated.

    In our case I have such scripts (you need something that will run all the scripts on the right files with the right parameters anyway) that we run manually before release, because we write offline applications that we have to then build on the build server anyway, but putting them in revision control hooks (weblate communicates over git repository; pootle can communicate either over repository or via web api) or button in administration interface of your app would not be much extra work.

    The translate toolkit converters are usable from python via API, so writing a bit of glue to extract the templates from wordpress database and insert them back is not that hard, or you can write the glue in anything and pass the templates via pipes or files. And then you'll have dynamic websites, where the master copy can be edited in wordpress and then the translators do the work in the weblate/pootle. Normally the translators are different people from the copywriters, often even from completely different company, so it shouldn't matter much if they use different interfaces.

    Only disadvantage might be that both weblate and pootle, and translate toolkit on which both are based, are in python, so you need hosting that can support more than just php.



  • @gleemonk said:

    I wouldn't want to have them on a VPS because they are not qualified to look after it. Paying a hosting provider to keep a website up is a lot cheaper than paying somebody to look after your VPS.

    Then I should add, that I am not sure about pootle, but the weblate team offers hosting, so you could write the glue and let others run the weblate instance.



  • @rc4 said:

    Wordpress is like the goatse of web security.

    That just means it's been pre-disastered.

    https://www.youtube.com/watch?v=DBSAeqdcZAM



  • I think your process has too many moving parts to be viable for a dinky website.



  • @blakeyrat said:

    That just means it's been pre-disastered.

    I welcome you taking a positive attitude for once.



  • @gleemonk said:

    I think your process has too many moving parts to be viable for a dinky website.

    It depends on how big it is. If it's just a couple of languages and if they have copywriters who know the languages on team, they can deal manually. But if they'll use external translators (we use a mix of people at various business partners halfway across the world and agency translators), weblate really makes the process much smoother. We really just push a button, ask translators to fill in what is missing and push another button and weblate tells us what is missing and warns about simple mistakes like mismatched placeholders, so the effort in maintaining the translations is really minimal.

    So it really depends on whether the business can amortize the initial work in setting it up. I'd estimate at least a week to properly configure and test everything and I already worked with it, so add at least another week to learn the necessary bits.



  • @Bulb said:

    It depends on how big it is.

    There will be 5 pages in two languages. Maybe six pages were they to use this outrageous feature where they can add new pages themselves 😄


  • Winner of the 2016 Presidential Election Banned

    @gleemonk said:

    using Wordpress

    Yeah, as @rc4 pointed out, this is actually a Go Directly To Jail right here. WordPress is more unsecure than Flash, and that's a fucking impressive feat.



  • @Fox said:

    Go Directly To Jail

    I retract my confession.


  • Winner of the 2016 Presidential Election Banned

    Seriously, though, there's practically a new zero-day for WordPress every day.



  • I just talked to a hosting guy yesterday who told me they're setting up automated updates for their Wordpress installations. A daily cronjob that runs wp update.

    I consider getting our shit hosted there.


  • Discourse touched me in a no-no place

    @gleemonk said:

    "Yeah your site is down. We turned it off because it generated a lot of traffic. We didn't bother to look what it was."

    That would probably attract a “Why the fuck are we paying you assholes money?” from me.

    We use Wordpress for some sites at work (I had nothing to do with that decision). The public facing ones have a read-only database, which I believe limits the damage that can be done…



  • @dkf said:

    That would probably attract a “Why the fuck are we paying you assholes money?” from me.

    Well I did write a stern email on behalf of our client... The hosting contract is between them and our client, so we can only document their negligence. (Though I read through the contract and nowhere does it say they won't turn off the site for stupid reasons, so I guess they were in the clear.)

    The first :wtf: was when I learned that the host for our Linux VM would be a Windows system. Lowered my expectations considerably. They can't even be bothered to install system updates on a regular basis. I think they didn't want to do it, and instead of rejecting to bid, offered at an inflated price in the hope that somebody else would be chosen, and now they're stuck with it because nobody else was asked.


Log in to reply