3

Very often you have to make a simple presentation website that doesn't need a complex CMS at all - a simple HTML file with some JavaScript would be fully sufficient.

However, it is still very useful to have an internationalization support. And then you have to use some actual framework or CMS; but this is so pointless because all you really need is just a translation support.

Please note that this is not a duplicate of questions such as this, because I could, of course, define a simple PHP file with translation array. But often you don't need to do this by yourself, but have a third person do it, so you need some simple administration area where you could edit the strings in a browser.

So please, does anyone know of a simple, file-based (ideally single file+internationalization files) PHP library with a simple login-restricted area where you can edit the strings in a browser?

I would definitely not like to reinvent the wheel :(

Note: this is a repost of this question, as it seems that that it's not ok to ask for recommendations on Stack Overflow anymore

1 Answer 1

1

I hope not being off topic as suggesting an hybrid solution, based on simple HTML files and using a CMS as a glue.

So, one possibility would be using the MODx CMS (Evolution branch), together with the YAMS module. Despite MODx is a CMS, it is very modular and you can use it only as a glue. Templates can be stored in external text files and loaded through the LoadTemplate plugin.

Here's for instance the code of a MODx snippet that loads text from an (X)HTML text file, from a different folder depending on the language:

<?php
return file_get_contents($modx->config['base_path'] .$lang.'/'.$id.'.xhtml');
?>

Assuming that we name this snippet GetSomePage, calling the French translation for document with id 7 would be as easy as:

[!GetSomePage? &lang=`fr` &id=`7` !]

Putting the snippet call in the template that your document uses, it would be

[!GetSomePage? &lang=`fr` &id=`[*id*]` !]

So, you could manage your pages using MODx's document tree and leave your page in files that you could upload to the server either by FTP or from within MODx.

By using the YAMS module/snippet/plugin, you can create template variables for each kind of translated text (title, description, every field you want). Template variables support default values, so that for each translation, the template variables could call the snippet that would load the text file.

MODx Evolution has some parser limits, so that I cannot totally guarantee this solution would work, but my experience is that when encountering parser limits, most of them can be circumvented with a little bit of imagination.

Expect some initial effort to learn the MODx jargon, setting YAMS, and creating a basic snippet like the one above, but it will pay if you often do multilingual sites, as once set you can reuse the logic of one site to other websites.

1
  • The Evolution branch of MODx was recently renamed Evolution CMS and now has a dedicated website: evo.im . Lot of (old) help topics can also be found in the MODx forums, athough thus is currently more used for MODx Revolution: forums.modx.com In the forum is a YAMS section.
    – OuzoPower
    Nov 29, 2017 at 14:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.