Member
Member
vincent3569   22-09-2017, 10:04
#1

hi
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 ?

Administrator
Administrator
acrylian   22-09-2017, 10:14
#2

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.

Member
Member
vincent3569   22-09-2017, 10:22
#3

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?

Member
Administrator
Administrator
acrylian   22-09-2017, 10:32
#5

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.

Member
Member
vincent3569   22-09-2017, 10:39
#6

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?

Member
Member
vincent3569   22-09-2017, 10:48
#7

basically, my plugin have this structure:

`

`

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

Administrator
Administrator
acrylian   22-09-2017, 12:15
#8

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);

  
Powered By MyBB, © 2002-2026 MyBB Group.
Made with by Curves UI.