Make WordPress Core

Opened 3 years ago

Closed 23 months ago

Last modified 23 months ago

#58658 closed enhancement (fixed)

WP_Locale add get_month_genitive() method

Reported by: Tkama Owned by: swissspidy
Priority: normal Milestone: 6.8
Component: I18N Version: 4.4
Severity: minor Keywords: has-patch
Cc: Focuses:

Description

The WP_Locale class has get_month() and get_month_abbrev() methods, but does not have get_month_genitive(). It should be there as well.

We should add such a code:

	/**
	 * Retrieves the full translated month in genitive case by month number.
	 *
	 * @since 6.2.3
	 *
	 * @param string|int $month_number  From 1 to 12. If a number less than 10 is
	 *                                  passed in integer or string format, a '0' will be added before it.
	 *
	 * @return string Translated full month name in genitive case.
	 */
	public function get_month_genitive( $month_number ) {
		return $this->month_genitive[ zeroise( $month_number, 2 ) ];
	}

Attachments (1)

diff.patch​ (1.1 KB ) - added by Tkama 3 years ago.

Download all attachments as: .zip

Change History (7)

@Tkama
3 years ago

#1 @SergeyBiryukov
3 years ago

  • Component General → I18N
  • Version 6.2.2 → 4.4

Thanks for the ticket! Setting the version to 4.4 as per [35517] / #11226.

#2 @swissspidy
2 years ago

  • Keywords has-patch needs-refresh added
  • Milestone Awaiting Review → 6.8
  • Owner set to swissspidy
  • Status new → reviewing

This ticket was mentioned in ​PR #7753 on ​WordPress/wordpress-develop by ​@ankitkumarshah.


2 years ago
#3

  • Keywords needs-refresh removed

Trac Ticket: Core-58658

### Summary

This pull request introduces a new utility function, get_month_genitive(), in the WP_Locale class to enhance localization capabilities. This function provides the genitive form of month names, which is necessary for languages that require different grammatical cases depending on context. The function accepts a month number as a string (e.g., ‘01’ for January) or an integer (e.g., 1 for January), and zero-pads numbers less than 10 automatically when an integer is provided.

### Changes

Added get_month_genitive() Function:

  • The function accepts month numbers from ‘01’ to ‘12’ as a string or as an integer from 1 to 12.
  • If provided as an integer, the function pads single-digit months to two digits automatically, ensuring consistent formatting.
  • Returns the translated month name in genitive case based on the site locale.


### Benefits

  • Enhanced Localization: Improves date formatting for languages that require genitive forms, making WordPress output more natural and grammatically correct in languages such as Russian or Polish.
  • Flexible Input Handling: The function accommodates both string and integer inputs, providing flexibility and simplifying month number handling.

### Example Usage

// Example of retrieving the genitive form of a month in a localized context.
$date_locale = new WP_Locale();
$genitive_month = $date_locale->get_month_genitive(1); // Outputs 'января' in Russian.

This ticket was mentioned in ​PR #7756 on ​WordPress/wordpress-develop by ​@ankitkumarshah.


2 years ago
#4

Trac Ticket: core 58658

### Summary

This pull request introduces a new utility function, get_month_genitive(), in the WP_Locale class to enhance localization capabilities. This function provides the genitive form of month names, which is necessary for languages that require different grammatical cases depending on context. The function accepts a month number as a string (e.g., ‘01’ for January) or an integer (e.g., 1 for January), and zero-pads numbers less than 10 automatically when an integer is provided.

### Changes

Added get_month_genitive() Function:

  • The function accepts month numbers from ‘01’ to ‘12’ as a string or as an integer from 1 to 12.
  • If provided as an integer, the function pads single-digit months to two digits automatically, ensuring consistent formatting.
  • Returns the translated month name in genitive case based on the site locale.

### Example Usage

// Example of retrieving the genitive form of a month in a localized context.
$date_locale = new WP_Locale();
$genitive_month = $date_locale->get_month_genitive(1);

#5 @swissspidy
23 months ago

  • Resolution → fixed
  • Status reviewing → closed

In 59494:

I18N: Add new WP_Locale::get_month_genitive() method.

Complements existing helper methods such as WP_Locale::get_month_abbrev().

Props ankitkumarshah, Tkama, SergeyBiryukov.
Fixes #58658.

Note: See TracTickets for help on using tickets.