• Resolved knzzz

    (@knzzz)


    How can I translate the Footnotes’ heading using WPML. I scanned the plugin for strings but couldn’t find the heading I entered. How should I do this?

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Contributor pewgeuges

    (@pewgeuges)

    Hi @knzzz,

    Thanks for the topic, good question, as it doesn’t work with the Polylang translation manager either (https://www.ads-software.com/support/topic/reference-container-heading-translations-and-a-collapse-feature/) and requires editing the Footnotes plugin like in https://www.ads-software.com/support/topic/reference-container-heading-translations-and-a-collapse-feature/#post-14704343

    Does WPML feature a string translation panel? If so, the name of the string to look out for is footnote_inputfield_references_label.

    The Footnotes plugin comes with an included wpml-config.xml file and therefore should work out of the box. If it does not, please keep us informed. Thank you.

    Thread Starter knzzz

    (@knzzz)

    I searched footnote_inputfield_references_label in “String Translation” in WPML but couldn’t find any matches.

    Thread Starter knzzz

    (@knzzz)

    I contacted WPML and they helped me add the translation for the string. But the translations wont show up in the frontend. The WPML support person said “the options aren’t retrieved by the plugin using get_option function”. What should I do?

    Plugin Contributor pewgeuges

    (@pewgeuges)

    @knzzz,

    I’m so sad that Footnotes does not work out of the box because its developer missed out on the best practice of doing nothing before WordPress runs the plugins_loaded hook. Strings are loaded too early from the database so that other plugins have no opportunity to filter them, and you also noticed that this string is invisible to WPML.

    As mentioned, we’ve had a similar issue 3??days earlier, and Polylang Author @chouby fixed it at Footnotes’ end. See @chouby’s assessment: https://www.ads-software.com/support/topic/plugin-string-translations-ineffective/#post-14714185, and how I posted it as a quick fix for fellow User @neondlight 8?hours ago: https://www.ads-software.com/support/topic/reference-container-heading-translations-and-a-collapse-feature/#post-14717295

    Sadly I can’t test it with WPML that I don’t have access to, but I guess that WPML has less tolerance than Polylang, and anyway the Footnotes plugin needs to be fixed for the translated strings to display on public pages.

    Hopefully you will find footnote_inputfield_references_label in “String Translation” after replacing the last four lines of plugins/footnotes/footnotes.php with this code (you may skip the docblock if you wish):

    
    /**
     * Allows other plugins to filter the options.
     *
     * @since TBD [after 2.7.3]
     * 
     * @contributor @chouby
     * @link https://www.ads-software.com/support/topic/plugin-string-translations-ineffective/#post-14714185
     * 
     * @reporter @neondlight
     * @link https://www.ads-software.com/support/topic/reference-container-heading-translations-and-a-collapse-feature/
     * 
     * Plugins should follow best practices, one of which is to do nothing before 
     * the plugins_loaded action is fired, or other plugins won’t filter options.
     */
    add_action( 'plugins_loaded', function() {
    
    	// Initialize the Plugin.
    	$g_obj_mci_footnotes = new Footnotes();
    	// Run the Plugin.
    	$g_obj_mci_footnotes->run();
    
    } );
    

    In other words: The last four lines as in https://plugins.trac.www.ads-software.com/browser/footnotes/tags/2.7.3/footnotes.php?rev=2521062#L116 are wrapped into add_action( 'plugins_loaded', function() { and } );.

    If I still had commit access I’d release an instant bugfix, and you and everybody else would be out of trouble after updating the plugin. For the time being, for what it’s worth I’ve posted a link on Footnotes’ GitHub repo: https://github.com/markcheret/footnotes/issues/189 (but I can’t see the bug label added).

    Plugin Contributor pewgeuges

    (@pewgeuges)

    Thank you for getting in touch with WPML and reporting back. Sorry for not seeing your post as I was busy posting the above. Adding that code made translations show up in the frontend when testing it with Polylang, and it appears that WPML is experiencing the same issue and will benefit from the same fix.

    I think that the solution above should work. Please keep us informed about the outcome.

    Our apologies for all the trouble!

    • This reply was modified 3 years, 2 months ago by pewgeuges.
    • This reply was modified 3 years, 2 months ago by pewgeuges.
    Thread Starter knzzz

    (@knzzz)

    Sadly, the above fix didn’t work. The footnote_inputfield_references_label did show up (and the translations were added), but the translations were not visible in the frontend.

    Plugin Contributor pewgeuges

    (@pewgeuges)

    Then please try this patch, posted 3?days ago (https://www.ads-software.com/support/topic/reference-container-heading-translations-and-a-collapse-feature/#post-14704343), before the above. About this one I’m absolutely sure that it works. This code needs to be added in plugins/footnotes/class/task.php at line?2797. Inside the switch statement, every added language has its case statement with a two-letter language code:

    
    $l_a_lang = explode( '-', get_bloginfo( 'language' ) );
    $l_s_lang = $l_a_lang[ 0 ];
    switch ( $l_s_lang ) {
      case 'xx': 
        $l_str_reference_container_label = 'Label in Xx'; 
        break;
      case 'yy': 
        $l_str_reference_container_label = 'Label in Yy'; 
        break;
      case 'zz': 
        $l_str_reference_container_label = 'Label in Zz'; 
        break;
      default: 
        $l_str_reference_container_label = $l_str_reference_container_label; 
    }
    

    I’m baffled that a patch that works for Polylang does not for WPML; if you are using some other free plugin with configurable strings working with WPML, I’d like to investigate how it’s done, to get clues about what it takes to properly fix the bug. I’ve already looked around but didn’t find any working example (beside configuring another plugin that failed likewise).

    Thread Starter knzzz

    (@knzzz)

    Hello,
    This one worked, thank you.
    I’m not using any other plugins other than those provided in the WPML bundle which includes

    • WPML Media (Version 2.6.4)
    • WPML Multilingual CMS (Version 4.4.10)
    • WPML SEO (Version 2.0.1)
    • WPML String Translation (Version 3.1.8)
    • WPML Translation Management (Version 2.10.6)
    Plugin Contributor pewgeuges

    (@pewgeuges)

    Hello @knzzz,

    Thank you for your feedback and insight. I’m glad to hear that this code solves the problem. Now we need to get this to work out-of-the-box and save you the trouble of editing the plugin after each update.

    Would you like to tell and send a link to WPML Support how plugin developers are struggling to make plugins WPML compatible and may wonder what it takes beyond wpml-config.xml? So far I’ve found https://wpml.org/documentation/support/achieving-wpml-compatibility-for-your-themes-and-plugins/#6 and https://wpml.org/forums/topic/add-custom-string-to-translate/ which don’t seem to cover our use case. Please tell them too that the problem is with configurable strings, not hard-coded strings handled by GetText. Documentation for plugin developers is wanted. So far, after applying a patch, the Footnotes plugin will already work with the free version of another translation manager, and we need just to know how to fix it for WPML.

    Thank you!

    • This reply was modified 3 years, 2 months ago by pewgeuges.
    • This reply was modified 3 years, 2 months ago by pewgeuges.
    Plugin Contributor pewgeuges

    (@pewgeuges)

    @knzzz

    Just one last, little question, please. Did you already open the options page of the Footnotes plugin, and save the first tab?

    I’m asking this question because I’ve got aware that while the reference container label is not in the database, it cannot be filtered. That is in fact what WPML Support alluded to when responding to you:

    The WPML support person said “the options aren’t retrieved by the plugin using get_option function”.

    In laymans terms, that means that you should save the options to the database in order for the plugin to retrieve them using get_option function.

    Sorry please for not seeing this before.

    As a consequence, after performing this action you may update Footnotes any time without worrying about the added code being overwritten. The translations as defined in the String Translation pane should keep working.

    There is also another translatable string in the Footnotes plugin: The read-on label. It has been added in November?2020 for version?2.1.0. (Up to then, this label relied on GetText.) This string matters if tooltips are not deactivated and if tooltip truncation is kept turned on. It is configurable under the second tab of the plugin’s options page. Each tab has its own DOM and is stored separately in the database (while other plugins may have tabs only as a display convenience and save all settings together).

    Worst is, when adding that string, I missed out on updating the wpml-config.xml file. Apologies for that.

    If you are using tooltip truncation, please update also wpml-config.xml by adding the tag <key name="footnote_inputfield_readon_label" /> next line:

    
    <wpml-config>
    	<admin-texts>
    		<key name="footnotes_storage">
    		    <key name="footnote_inputfield_references_label" />
    		    <key name="footnote_inputfield_readon_label" />
    		</key>
    	</admin-texts>
    </wpml-config>
    

    Should there still be any problem, or if you require further support, be sure to keep in touch, we’re more than happy to help.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Heading translation with WPML’ is closed to new replies.