Considerations for running Lang Forge on WordPress Multisite installations.
Per-Site Configuration
In a Multisite setup, each site has its own independent Lang Forge configuration. Languages, translations, and settings are stored per-site in each site’s database tables.
php
// Each site in a network can have different languages
// Site 1 (example.com): Russian + English
// Site 2 (blog.example.com): Russian + German + French
// Each site is fully independentShared Content Across Network Sites
If you need to share translations across network sites, you can build a custom sync mechanism:
php
/**
* Sync a translation group across network sites.
* Call this after creating translations on the source site.
*/
function theme_sync_translations_to_network($post_id, $target_blog_id) {
$source_post = get_post($post_id);
$source_lang = lf_get_post_language($post_id);
$translations = lf_get_post_translations($post_id);
switch_to_blog($target_blog_id);
// Create or update the post on the target site
$target_post_id = wp_insert_post([
'post_type' => $source_post->post_type,
'post_title' => $source_post->post_title,
'post_content' => $source_post->post_content,
'post_status' => $source_post->post_status,
]);
if ($target_post_id && !is_wp_error($target_post_id)) {
LF_Post_Translation::instance()->set_post_language($target_post_id, $source_lang);
}
restore_current_blog();
return $target_post_id;
}php
// Generate a translation status report across all sites
function theme_network_translation_report() {
$sites = get_sites();
$report = [];
foreach ($sites as $site) {
switch_to_blog($site->blog_id);
$languages = lf_get_languages();
$site_data = [
'url' => get_home_url(),
'languages' => [],
];
foreach ($languages as $code => $lang) {
$count = new WP_Query([
'post_type' => 'any',
'meta_key' => '_lf_language',
'meta_value' => $code,
'fields' => 'ids',
]);
$site_data['languages'][$code] = $count->found_posts;
}
$report[$site->blog_id] = $site_data;
restore_current_blog();
}
return $report;
}—