• Resolved sneike

    (@sneike)


    Hi, thanks for your great plugin. I am doing some test before switching my main website from qtranslate to polylang, and I have two questions:

    1. I’d like to translate some template’s strings, the text fields are inside the theme options panel, specifically they are labeled “Top bar text” and “Copyright text”. I tried to follow some instructions I found here to modify the functions.php file, but I couldn’t manage it to work. How can I do that, if possible?

    2. I have 3 languages in my website, but if a particular post is written only in two languages, I’d like to show the language switcher with only those two flags. Can we do this?

    (even if I think it’s not useful for this matter: permalinks setting is “post name”, and I use a static front page)

    Thanks for your support.
    DNL

    https://wordpress.org/plugins/polylang/

Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Author Chouby

    (@chouby)

    Hi!

    1. You don’t have to modify your theme, but you will have to dig in it (or ask the author to help) to find the option names and setup a wpml-config.xml file.

    2. One way is to use a custom language switcher. Using a css rule can do the trick for a language switcher in menu or in Polylang widget:

    .no-translation {
      display: none;
    }

    Thread Starter sneike

    (@sneike)

    Thanks Chouby for your answer.

    1. this is where the theme defines the option I’d like to translate:

    $thb_field = new THB_TextField('top-bar-text');
    		$thb_field->setLabel( __('Top bar text', 'thb_text_domain') );
    		$thb_field->setHelp( __('The text will be displayed inside the header top bar (Note: accepts basic HTML).', 'thb_text_domain') );
    	$thb_container->addField($thb_field);
    
    	$thb_field = new THB_TextField('copyright');
    		$thb_field->setLabel( __('Copyright text', 'thb_text_domain') );
    		$thb_field->setHelp( __('The copyright text will be displayed at the bottom of the site (Note: accepts basic HTML).', 'thb_text_domain') );
    	$thb_container->addField($thb_field);

    I tried to create the wpml config xml, but I couldn’t make it work. Could be more precise?

    2. this should be the code of the custom language switcher

    <ul><?php pll_the_languages(array('hide_if_no_translation'=>1)); ?></ul>

    where should I insert it?

    Thanks
    DNL

    Plugin Author Chouby

    (@chouby)

    Hello,

    1. We can suppose (not sure) that ‘top-bar-text’ and ‘copyright’ are options names. But usually, they are stored in general theme option. You should be able to find it by looking for the function ‘update_option’.

    2. You can put it wherever you want in your theme. Most people put it in header.php. That’s useful if you want to put the switcher outside the menus and widgets sidebars. Otherwise the css rule is easier, as it’s sometimes hard not to break the theme layout when inserting a new template tag. In any case, if you do some modifications, it’s better to do them in a child theme.

    Thread Starter sneike

    (@sneike)

    Thanks for your answer Chouby, and sorry for my late reply.

    1. I can’t find the definition of the function you say. I’ll ask to the authors of the template. In the meanwhile, supposing that “top-bar-text” and “copyright” are the correct names, what should I do? I put a file called wpml-config.xml into /wp-content/polylang/ containing this:

    <wpml-config>
        <admin-texts>
    		<key name="top-bar-text" />
    		<key name="copyright" />
        </admin-texts>
    </wpml-config>

    but as far as I can understand nothing seems to change. Is this procedure correct and complete?

    2. The css rule works fine, since I’m using the language switcher in the sidebar. Anyway, if I check the option to hide the current language and if that specific post is not available in other languages, in the sidebar I’d see the widget’s title without any flag. Is it possible to completely hide the widget if there is not any other language except the current one?

    Thanks for your support
    Daniele

    Thread Starter sneike

    (@sneike)

    About the number 1, template’s authors replied me that I need to use a serialized array. Now the strings correctly appear in the polylang tab. Anyway it looks like the polylang setting is ignored, on the front end I keep seeing the same untranslated string πŸ™

    Plugin Author Chouby

    (@chouby)

    Hi!

    1. Finally, what is the content of your wpml-config.xml?

    2. No. That’s the issue with pure css rule. I will setup a filter in v1.5 that will allow more flexibility for developers.

    Edit polylang/include/switcher.php at line 123 and replace:

    $args = wp_parse_args($args, $defaults);

    by

    $args = wp_parse_args($args, $defaults);
    $args = apply_filters('pll_the_languages_args', $args);

    This modification will be done in v1.5 so you won’t loose it at update.

    Then to take profit of this new filter, create a new file pll-tweaks.php with:

    <?php
    /*
    Plugin name: Polylang tweaks
    */
    add_filter('pll_the_languages_args', 'pll_hide_if_no_translation');
    function pll_hide_if_no_translation($args) {
      $args['hide_if_no_translation'] = 1;
      return $args;
    }

    Upload this file in your plugin directory and activate the new plugin. Not tested but it should work.

    Thread Starter sneike

    (@sneike)

    1. This is my xml file:

    <wpml-config>
        <admin-texts>
            <key name="thb_theme_options_extremist">
                <key name="top-bar-text" />
                <key name="copyright" />
            </key>
        </admin-texts>
    </wpml-config>

    Anyway the template’s authors replied me that they found a bug, so it’s not a polylang issue. Thanks for your support πŸ˜‰

    2. Thanks, tonight I will try your instructions and I’ll let you know the results.

    Thanks!

    Thread Starter sneike

    (@sneike)

    2. You’re great Chouby, your solution works.
    Just one thing: as it is, it depends by the widget setting to hide the current language which must be checked. But let’s say I don’t want to hide the current language, the widget shouldn’t appear if the current language is the only one available, don’t you think so?

    Plugin Author Chouby

    (@chouby)

    Yes that’s a limitation. The current widget is quite basic and is not hidden if only the current language is avalaible and you chose not to hide the current language.

    If you want to have such a widget, you will have to code it yourself, using the ‘raw’ argument in pll_the_languages which let you get all necessary informations to make a fully custom language switcher.

    Thread Starter sneike

    (@sneike)

    Thanks Chouby, I’ll hide the current language, so that the flags are shown correctly πŸ™‚

    Anyway, testing this solution, I just noticed one pretty important thing: the flag of the language is shown even is the post is a draft. Let’s say I published a post in italian, but I’m still translating the relative spanish version, it shouldn’t show the flag and the link to the draft (which won’t work if you’re not logged in). You can see an example of this situation here (it’s just a test website that I use). The italian post is already published, while the spanish one is just a draft.

    Thanks

    Plugin Author Chouby

    (@chouby)

    Hi!

    You are right. The language switcher does not check if the user has the right to read the post before creating the link.

    You are the first to notice this but I believe this is important. So I added this functionnality in the current development version (1.5dev32).
    http://downloads.wordpress.org/plugin/polylang.zip

    Thread Starter sneike

    (@sneike)

    Great, thanks! I tested it out and it works perfectly!

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Translate strings, and language switcher question’ is closed to new replies.