Programmatically create menu link language relation in Drupal 7. This example takes a certain taxonomy vocabulary by id and creates language relations to menu links by terms relations. You might need it when you create custom view that needs menu link language relations.
Source code viewer
// language relation $terms = taxonomy_get_tree(1); $mlids = db_query('SELECT tid, mlid FROM {taxonomy_menu} WHERE vid = 1')->fetchAllKeyed(); foreach($terms as $term) { // get all engilsh terms if($term->language == 'en') { //get other languages foreach($terms as $term2) { if($term2->i18n_tsid == $term->i18n_tsid) $lang_terms[$term2->language] = $term2->tid; } //create language relations $translation_set = i18n_translation_set_create('menu_link'); foreach ($lang_terms as $lang => $tid) { $item = menu_link_load($mlids[$tid]); $translation_set->add_item($item, $lang); $item['i18n_tsid'] = $translation_set->tsid; menu_link_save($item); } $translation_set->save(TRUE); } } menu_rebuild();Programming Language: PHP