• Resolved carestad

    (@carestad)


    Hi

    I’m having an issue where I can’t use my theme’s translation for my custom taxonomies in functions.php. I want to be able to do this:

    function foo() {
     register_taxonomy(
        'genre',
        'post',
        array(
          'labels' => array(
            'name' => __('Genres'),
            'singular_name' => __('Genre')
          ),
          'rewrite' => array('slug' => __('genre')),
          'capabilities' => array(
            'assign_terms' => 'edit_posts',
            'edit_terms' => 'manage_categories'
          )
        )
      );
    }
    add_action('after_theme_setup', 'foo');

    Where __('Genre') never gets translated in functions.php, but in single.php it works. Maybe I just haven’t found the right hook for the function yet? I’ve tried using init, after_theme_setup, load_textdomain.

    Does anyone know how to make this work, or isn’t it possible?

Viewing 3 replies - 1 through 3 (of 3 total)
  • I’ve not tried using a custom taxonomy in conjunction with a translation but the first thing that leaps out at me is that you haven’t made the Genre strings translatable – eg:

    'name' => __('Genres', 'textdomain_name')
    'singular_name' => __('Genre', 'textdomain_name')
    Thread Starter carestad

    (@carestad)

    Oh God, feel like such an idiot now. In my functions.php i had:

    load_theme_textdomain('foo', get_template_directory() . '/languages');
    load_child_theme_textdomain('foo', get_stylesheet_directory() . '/languages');

    Changing it to

    load_theme_textdomain('foo', get_template_directory() . '/languages');
    load_child_theme_textdomain('bar', get_stylesheet_directory() . '/languages');

    And adding the textdomain as a second argument to the _e() and __() functions made it work ('name' => __('Genre', 'bar')).

    Thanks!

    Thread Starter carestad

    (@carestad)

    And the after_setup_theme hook didn’t work. I had to use init for the function that calls register_taxonomy().

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Use of localization functions within register_taxonomy in functions.php’ is closed to new replies.