Tagged: 

Viewing 1 reply thread
  • Author
    Posts
    • #6701
      scalait
      Member

      I am talking about the function “post_type_labels” in the class “Piklist”.

      There is a wrong use of the WordPress translation functions. You have to use placeholders in this function.

      This __(self::singularize($label), 'piklist') does not work, because the translatable strings are parsed from special function calls in the source-code, they are not obtained at run-time.

      More information you can find in the documentation:

      https://codex.wordpress.org/I18n_for_WordPress_Developers

      Part “Placeholders”

      So here is the old code:

      
        public static function post_type_labels($label)
        {
          return array(
            'name' => __(self::singularize($label), 'piklist')
            ,'singular_name' => __(self::singularize($label), 'piklist')
            ,'all_items' => __('All ' . self::pluralize($label), 'piklist')
            ,'add_new' => __('Add New', 'piklist')
            ,'add_new_item' => __('Add New ' . self::singularize($label), 'piklist')
            ,'edit_item' => __('Edit ' . self::singularize($label), 'piklist')
            ,'new_item' => __('Add New ' . self::singularize($label), 'piklist')
            ,'view_item' => __('View ' . self::singularize($label), 'piklist')
            ,'search_items' => __('Search ' . self::pluralize($label), 'piklist')
            ,'not_found' => __('No ' . self::pluralize($label) . ' found', 'piklist')
            ,'not_found_in_trash' => __('No ' . self::pluralize($label) . ' found in trash', 'piklist')
            ,'parent_item_colon' => __('Parent ' . self::pluralize($label) . ':', 'piklist')
            ,'menu_name' => __(self::pluralize($label), 'piklist')
          );
        }
      

      I think this would be a right version of a “new code”:

      
        public static function post_type_labels($label)
        {
          return array(
            'name' => self::singularize($label)
            ,'singular_name' => self::singularize($label)
            ,'all_items' => sprintf(__('All %s', 'piklist'), self::pluralize($label))
            ,'add_new' => __('Add New', 'piklist')
            ,'add_new_item' => sprintf(__('Add New %s', 'piklist'), self::singularize($label))
            ,'edit_item' => sprintf(__('Edit %s', 'piklist'), self::singularize($label))
            ,'new_item' => sprintf(__('Add New %s', 'piklist'), self::singularize($label))
            ,'view_item' => sprintf(__('View %s', 'piklist'), self::singularize($label))
            ,'search_items' => sprintf(__('Search %s', 'piklist'), self::pluralize($label))
            ,'not_found' => sprintf(__('No %s found', 'piklist'), self::pluralize($label))
            ,'not_found_in_trash' => sprintf(__('No %s found in trash', 'piklist'), self::pluralize($label))
            ,'parent_item_colon' => sprintf(__('Parent %s:', 'piklist'), self::pluralize($label))
            ,'menu_name' => self::pluralize($label)
          );
        }
      

      The same problem can be found in the function “taxonomy_labels” in the class “Piklist”.

    • #6720
      Jason
      Keymaster

      Hey @scalait!

      Good catch! Thank you for pointing that out! 🙂

Viewing 1 reply thread
  • You must be logged in to reply to this topic.