Tag : polylang

Migration du blog de WordPress vers Hugo

Ça y est le blog est live avec Hugo et j’écris le premier post en markdown.

Le chemin a été long, mais parce que j’ai geeké d’une nouvelle manière … bon on est en 2026 vous avez déjà deviné : oui l’IA est derrière tout ça !

Tout a commencé par une question à Gemini : porter le blog de WordPress vers un site statique utilisant un générateur en Go… puis on a commencé à coder à coups de copier-coller : la conf et les templates Hugo, un premier Docker Compose avec un dump de la db de WordPress pour récupérer le contenu. L’idée c’était de coder un outil en Go qui ferait la conversion, ainsi tant que le rendu n’était pas satisfaisant je pouvais tout effacer et relancer l’import des posts.

Après beaucoup de réticence j’ai installé opencode mais pas sans l’enfermer dans un Docker. Puis j’ai découvert greywall, pi.dev et développer AI-Cabin mais ma plongée vers l’IA c’est une autre histoire, revenons au blog.

Donc je disais, ce portage a été fait avec l’assistance d’IA de plus en plus performante, mais toutefois limitées car pour garder le contrôle sur mes données j’ai pas ouvert de comptes chez les grands acteurs. J’ai utilisé Gemini car j’ai déjà un compte Google et c’est un blog qui est déjà public, ensuite je suis passé aux modèles de Scaleway.

Les 3 gros éléments de ce portage :

  • un importer : code en Go qui utilise sqlc pour lire la db et html-to-markdown/v2 pour transformer le (pseudo) html de WordPress en fichiers markdown.
  • une conf Hugo multilingue
    • et là, la feature que je n’avais jamais finalisée : le truc qui marchottait avec gengo et que j’ai pas fini sur polylang : la vue agrégée multilingue était enfin possible ! une langue virtuelle all dans la config Hugo et une duplication virtuelle du contenu français ou anglais vers cette ‘dimension’ telle que définie depuis Hugo v0.156.
  • enfin un outil de comparaison du rendu Hugo contre une capture wget du WordPress (avec plein de règles de tolérance pour les trucs que j’ai choisis de changer)

Les grandes fonctionnalités :

  • import reproductible et assez fidèle malgré une conversion en markdown
    • grâce à un plugin sur html-to-md qu’il faudra que je publie rapidement : parce que le html de WordPress a pas mal de dingueries :
      • on pense déjà au saut de lignes qui font des paragraphes (wpautop)
      • les smileys
      • les conversions typographiques (ex les jolis guillemets)
  • import des commentaires (en statique car bon c’était désactivé depuis longtemps … merci les spammers)
  • préservation des URI parce que « Cool URIs don’t change » — j’en parlais déjà en 2010 — en configurant Hugo pour reproduire en partie la structure de WordPress, le reste à coups de redirects générés.

Voilà, c’est live, je vais pouvoir virer PHP du server, un peu moins de stress vis-à-vis des failles 😅

From gengo to polylang: updating the theme

So I postponed hacking a mode with multiple languages on the same page and decided to set polylang on my production site (hem) my blog.

But Gengo was using some customized template tags so the theme was adapted to it and this needed to be changed.

With polylang it’s a lot simpler, all navigation is handled by filters, so only thing really custom had to be written:

Basically my hacked version of the_translations had to be ported. And to keep it simple it can even be part of the functions.php file in the theme and use the pll_the_languages function.
I want to display the other language title prefixed by “Language version” written in this language. As the gettext like functions would only return strings in the current language, I hardcoded those strings, but adding them in Polylang admin “strings translation” would have been nice…
So here is the code:

 $translation_title=array(
    'en' => "English version:", 
    'fr' => "Version française : ");
function my_translations() {
    global $post;
    global $translation_title;
    $post_id=$post->ID;
    if ( function_exists('pll_the_languages') ) {
        $translations = pll_the_languages(array('post_id' => $post_id, 'hide_if_no_translation'=>1, 'hide_current'=>1, 'raw'=>1));
        if(!empty($translations)) {
            foreach($translations as $tr) {
                $trid=pll_get_post($post_id, $tr['slug']);
                ?><li lang="<?php echo esc_attr($tr['slug']);?>"><?php echo $translation_title[$tr['slug']]; ?><a hreflang="<?php echo esc_attr($tr['slug']);?>" href="<?php echo esc_url($tr['url']);?>" rel="alternate"><?php echo get_the_title($trid); ?></a></li><?php
            }
        }
    }
}

Instead of porting the old theme, I did build a new one based on WordPress’ Twenty Twelve updated with my previous header and dark color scheme.
I also played with a few css3 features for more neon light effects 🙂

And here it is !

From gengo to polylang: importing data

As you might know, my blog is using gengo to enable translations.

But gengo is an old unmaintained plugin (I’m even running a custom version that I recently needed to fix again) so I’d like to migrate away.

Recently, I studied the available options (thanks to Multilingual WordPress page) and selected Polylang. This one seams to be what Gengo could have been with a rewrite: no extra database tables but using WP3 custom taxonomies. (I can’t find the message but I remember Pixline telling this would be the way to go, so…).

Anyway, I started to test Polylang, what it misses compared to Gengo, is the ability to really mix languages on the same page, so it will need some customizations before replacing Gengo here, but it will come.

It’s only a few days layer that I found the WPML to Polylang plugin.
This basically triggered the development of Gengo to Polylang a plugin to import translations informations from Gengo to Polylang.

It seams to work… I missed the Site Title and Tagline (but they are no longer translated on my blog so I don’t need it 😕 ) and I did take some shortcut for terms (tags & categories) that are the same in both languages.
UPDATE 2014-02-04: I fixed that as it caused the tag archive to contain both english and french posts so… also fixed the Title and Tagline part.

So if you still have a Gengo powered blog and want to migrate, the code could help you, but don’t just run it blindly, make a backup, setup a test instance and be prepared to hack the code ! You have been warned !