• Resolved theyuv

    (@theyuv)


    Hello,

    Categories for my site are generated dynamically by users.

    Therefore, when submitting a post, 1) I check if the category exists, 2) If not, I enter it with wp_insert_term().

    For the case where I insert the term, I would also like to insert its translation (I have a way of getting the translation of the user’s term).

    Is it safe to simply use WPGlobus_Utils::build_multilingual_string() for the $name field of wp_insert_term() (ie: wp_insert_term(WPGlobus_Utils::build_multilingual_string( $some_array ), $taxonomy );)?

    Is this the way to programmatically insert a term with its translations?

    Thank you

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Contributor Alex Gor

    (@alexgff)

    yes.
    but you need to prevent duplicate terms.
    Please check filter ‘filter__pre_insert_term’
    see wpglobus\includes\class-wpglobus-filters.php:352
    see wpglobus\includes\wpglobus-controller.php:42

    • This reply was modified 8 years ago by Alex Gor.
    Thread Starter theyuv

    (@theyuv)

    Thanks,

    I use term_exists before calling wp_insert_term. But I’ll also look at the filter you referenced.

    I noticed also that I need to specify that the slug is the default language version of the multilang string…Otherwise, the slug defaults to a slug of the full multilang String.

    Thread Starter theyuv

    (@theyuv)

    Hello again,

    Does the term_exists() function get filtered by wpglobus?
    When I check if a term exists, I have to check if the multilanguage term exists (ie: “{:en}term{:}{:ru}term{:}”).

    Is there a way to check if the term exists using the current locale?

    Thanks.

    Plugin Author TIV.NET INC.

    (@tivnetinc)

    Term exists or term name translated?

    It exists even if not translated.

    Thread Starter theyuv

    (@theyuv)

    Maybe I didn’t explain my case well enough.

    Before inserting a term with wp_insert_term(), I check that it exists with term_exists.

    However, at the moment, I have to first convert the term into its multilingual version before using the term_exists function.
    eg: term_exists("{:en}term{:}{:ru}term{:}"...

    This isn’t too much of an inconvenience but I was wondering if I can check if a term exists using the term itself
    eg: term_exists("term"...

    Thanks.

    Plugin Author TIV.NET INC.

    (@tivnetinc)

    Makes sense. There is a utility method to build the {:}-string.

    Anyway, what if the term exists but not translated?

    I am trying to add a new term, “Something in RU”, and to check if exists, should look for
    {:en}Something in EN{:}{:ru}Something in RU{:}.
    But, I do have term Something in EN. It just was not translated. So, I create a new term, with two languages….

    Need to think more about this.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Inserting terms as multilingual strings’ is closed to new replies.