Skip to content

Instantly share code, notes, and snippets.

@robertuniqid
Created April 14, 2021 11:53
Show Gist options
  • Save robertuniqid/61dc1852df1c34a753d167c88a4945af to your computer and use it in GitHub Desktop.
Save robertuniqid/61dc1852df1c34a753d167c88a4945af to your computer and use it in GitHub Desktop.
WordPress Deepl Locale -> Lang Map
<?php
if( !function_exists( 'wp_get_available_translations') )
require_once ABSPATH . 'wp-admin/includes/translation-install.php';
$deepl = [
"BG", "CS", "DA", "DE", "EL", "ES", "ET", "FI", "FR", "HU",
"IT", "JA", "LT", "LV", "NL", "PL", "RO", "RU", "SK", "SL", "SV", "ZH",
"EN-GB", "EN-US",
"PT-PT", "PT-BR"
];
$available_translations = wp_get_available_translations();
$data = [];
foreach( $available_translations as $available_translation_key => $available_translation ) {
$l = str_replace( '_', '-', strtoupper( $available_translation[ 'language' ] ) );
if( in_array( $l, $deepl ) ) {
$data[ $available_translation[ 'language' ] ] = $l;
continue;
}
if( strpos( $l, '-' ) === false )
continue;
$l = substr( $l, 0, strpos( $l, '-' ) );
if( in_array( $l, $deepl ) ) {
$data[ $available_translation[ 'language' ] ] = $l;
continue;
}
if( $l === 'EN' )
$data[ $available_translation[ 'language' ] ] = 'EN-US';
if( $l === 'PT' )
$data[ $available_translation[ 'language' ] ] = 'PT-PT';
}
wpep_debug_dump( $data );
exit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment