• Resolved samjeansoper

    (@samjeansoper)


    I am building a plugin that creates a custom post type which displays the gear in different players bags. I would like to share the site, but this is a work project so I cannot share a link to it. I’m hoping I am just glazing over some translation option and it can be resolved without needing to look at the front end.

    I am currently using sprintf(__('%1$s\'s %2$s:', $this->plugin_name ), $players_name, $equip_option)); for one of my translation phrases.

    MY ISSUE: I am translating this into French and the specific phrasing $players_name's $club_option has two additional words that vary based on the variable (le/la/les $equip_option de/d'$player_name). I was attempting to tackle the first word first, with the following context translation:

    $has_vowel = $this->is_vowel($players_name_metadata);	
    if($has_vowel == true) {
    	$players_name = _x($players_name_metadata, 'starts with vowel', $this->plugin_name);
    } else {
    	$players_name = _x($players_name_metadata, 'does not start with vowel', $this->plugin_name);
    }

    $this->is_vowel(); checks whether the player’s name starts with a vowel to define the use of de or d’ in the translation.

    Unfortunately, that conditional translation is not showing up when I run the plugin through POEdit. The %1$s\'s %2$s: part is showing up for translation, but there are no other options depending on context.

    Am I missing something about the context translation options? Is my code just out of order? Am I supposed to make a method to feed the variables and generate the correct translation string?

Viewing 1 replies (of 1 total)
  • Thread Starter samjeansoper

    (@samjeansoper)

    Nevermind, I figured it out. My solution was creating the following method, after I realized I didn’t need the feminine article for the equip_options:

    public function get_player_equip_context($player_name, $equip_option) {
    	$context = sprintf(_x('%1$s\'s %2$s:', 'default', $this->plugin_name ), $player_name, $equip_option);
    		
    	$has_vowel = $this->is_vowel($player_name);
    	$is_plural = $this->is_plural($equip_option);
    		
    	if($has_vowel == true) {
    		if($is_plural == true) {
    			$context = sprintf(_x('%1$s\'s %2$s:', 'plural article & vowel name', $this->plugin_name ), $player_name, $equip_option);
    		} else {
    			$context = sprintf(_x('%1$s\'s %2$s:', 'single article & vowel name', $this->plugin_name ), $player_name, $equip_option);
    		}
    	} else {
    		if($is_plural == true) {
    			$context = sprintf(_x('%1$s\'s %2$s:', 'plural article & non-vowel name', $this->plugin_name ), $player_name, $equip_option);
    		} else {
    			$context = sprintf(_x('%1$s\'s %2$s:', 'single article & non-vowel name', $this->plugin_name ), $player_name, $equip_option);
    		}
    	}
    	return $context;
    }
Viewing 1 replies (of 1 total)
  • The topic ‘Conditional French translation context dependent on variable’ is closed to new replies.