• Resolved dpowney

    (@dpowney)


    I’m trying to integrate Polylang into one of my plugins. When I register a custom string using pll_register_string() function I can see it show up in the Translations tab but then the string disappears from the list if I refresh the page. I can reproduce this easily by adding the following code in my theme, and then commenting out the pll_register_string() later to see if the string persists.

    function test_polylang() {
    	if ( function_exists( 'pll_register_string' ) ) {
    		pll_register_string( 'test', 'test value', 'my-text' );
    	}
    }
    add_action ( 'admin_init', 'test_polylang' );

    Am I doing something wrong or have I misunderstood what the pll_register_string() function does? I am trying to replicate WPML string translations. Note: I already have a wpml config file but the strings I’m trying to register are added by the admin user.

    Thanks,
    Daniel

    https://ww.wp.xz.cn/plugins/polylang/

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

    (@chouby)

    Hi!

    Polylang works differently from WPML.

    What you describe is the expected behavior. Think to register_post_type(). If you use it, a post type is created. You can save posts. If you comment the register_post_type(), then the post type is not displayed anymore (but posts are kept in DB). pll_register_string() has been created in the same spirit.

    If you want something persistent, then use icl_register_string() from the WPML API.

    Thread Starter dpowney

    (@dpowney)

    Excellent support! Makes sense now.

    Does Polylang support icl_register_string? If so, since this is deprecated in WPML, does Polylang support the wpml_register_single_string hook?

    Thanks
    Daniel

    Plugin Author Chouby

    (@chouby)

    icl_register_string() is supported. See https://polylang.wordpress.com/documentation/documentation-for-developers/compatibility-with-the-wpml-api/

    The new API with hooks introduced in WPML 3.2 is not yet supported but this is in my plans.

    Thread Starter dpowney

    (@dpowney)

    Thanks, marked as solved.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘string registered with pll_register_string disappears’ is closed to new replies.