• I would like to change the translation of a string for a particular language programmatically.

    Let’s assume a string has been registered (default EN):

    pll_register_string("my_string_domain", "House");

    In another part of the code I know the original registered string, the language in that the translation should be changed and the translation.

    $originalLang = "en";
    $original = "House";
    $targetLang = "de";
    $translation = "Haus";

    I’ve looked through the API and could not find any matching function, except of “pll_save_term_translations”. But that one is working with an associative array of “lang_code” => “term_id”. Since the translation is new, it has no “term_id” yet. So I cannot use it in this case. Maybe, someone has an idea for another approach to this problems?

    Best regards,
    ronhard.

    • This topic was modified 7 years, 5 months ago by ronhard.
Viewing 1 replies (of 1 total)
  • Normally, if you insert the terms using WP’s wp_insert_term(), you are returned a term ID and it’s corresponding taxonomy ID:

    https://codex.www.ads-software.com/Function_Reference/wp_insert_term

    So if you use it like this:

    $inserted_term = wp_insert_term( $args );

    .. you can find your term ID (provided WP did not return an error) in:
    $inserted_term[‘term_id’] or something like that.

    [[ although after re-reading your question, I am not sure you are working with strings or WordPress terms ]]

    • This reply was modified 7 years, 4 months ago by fungus.
Viewing 1 replies (of 1 total)
  • The topic ‘Edit String Translation Programmatically’ is closed to new replies.