Closed scooterlord closed 1 year ago
What does "set the language for that post" mean? There's nothing special in DB beside the ML tags. So yes, you can create a ML post by setting the fields with ML tags. However you have to be consistent with the languages being activated. We cannot guarantee the behavior if something is written in a wrong format.
The official API is not entirely clear but there are some functions that you may use quite safely (not subject to change) to pack the tags from a dictionary with keys = lang_code and values = text for each lang:
$lang_text = [ 'en' => 'english text', 'fr' => 'texte francais', '<other>' => ... ];
$ml_text = qtranxf_join_b( $lang_text );
// this should give '[:en]english text[:fr]texte francais[<other>]...[:]'
// then use it for the post
$post->content = $ml_text;
Unfortunately there's no public function to retrieve the active languages. You can get the codes from $q_config['enabled_languages']
but that's not so great to use such global. Consider that as a hack until there's an official API.
Hello and thanks for keeping this plugin alive!
Is there a way to create a post programmatically and set the language for that post?