plugin for personnal translation

I want to create a plugin to manage personnal translations needed on my website (and that can't be managed by multi-lingual site option).

can you explain what the general structure of this plugin have to be ?


  • acrylian Administrator, Developer
    edited September 2017

    I am sorry, I don't fully understand what this plugin is meant to do.

    If you are talking about extra translation/strong for your theme that are not part of the theme by default, you need to use an extended theme base translation. That's just the theme translation just with your custom additions. You get those easily by parsing it using Poedit again.

    Or do you want to put these extra strings into a separate plugin? That would be possible of course although I think that overcomplicates things. In that case you would have just to create a plugin based translation.

  • yes I have extra translations for my themes and I know how it works.

    In my case, I want extra translations for my content (i.e for using in blockcode).
    I don't know what I have to create in that plugin based translation (no admin interface, only some string to translate with gettext_pl().

    can you point me i the right direction?

  • acrylian Administrator, Developer

    That post is from 2008 when we used WordPress. Of course the link is broken now, we don't go through all … But you found it anyway…

    A plugn does not need to have a admin interface. Just put a function with strings or just an array within it that contains the gettexted strings to translated. Then create a plugin based translation and use calls of the function or array in your theme.

    Instead of using codeblocks extensively I would recommend maybe to use the multiplelayout plugins or theme based custom functions. Codeblocks are nice for quick things but you easily forget what you used where..… Use codeblock only when really necessary.

  • I read the documentation before asking my question :-)

    what do mean by

    use calls of the function or array in your theme

    can you give me a dummy example?

  • vincent3569 Member
    edited September 2017

    basically, my plugin have this structure:

    <?php /** * Plugin pour gérer les traductions personnelles de mon site, indépendament des thèmes utilisés. * * @package plugins * @subpackage seo */ $plugin_is_filter = 9|THEME_PLUGIN; $plugin_description = gettext_pl('Plugin to manage personnal translations of my site.', 'translations'); $plugin_author = "Vincent Bourganel (vincent3569)"; $plugin_version = '1.0'; function translated_strings() { $strings = array( gettext_pl('Hello World!', 'translations'), gettext_pl('Hello World, again!', 'translations') ); } ?>

    it's ok for you?
    with that, I can access to translated string in my pages/news where needed?

  • acrylian Administrator, Developer
    edited September 2017

    That would be like I had in mind. translated_strings() would better be named getTranslatedString() (we generally use camel case in Zenphoto in case you want to follow that writing). and get a parameter to access a specific strings since you want to use this on your theme.

    So like this:

    function getTranslatedString($index) {
        $strings = array(
            gettext_pl('Hello World!', 'translations'),
            gettext_pl('Hello World, again!', 'translations')
       return $strings[$index];
    $firststring = getTranslatedString(1);  

    And for more flexibility maybe add:

    function printTranslatedString($index) {
    echo getTranslatedString($index);

    I also would recommend to use a class with static methods as a wrapper so your plugin will avoid possibly naming conflicts.

    class vincentsStrings { //best match the plugin name somehow
       static getString($index) {
    $firststring = vincentsStrings::getString(1);
Sign In or Register to comment.