Make WordPress Core

Opened 20 months ago

Closed 2 months ago

Last modified 2 months ago

#58658 closed enhancement (fixed)

WP_Locale add get_month_genitive() method

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

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 20 months ago.

Download all attachments as: .zip

Change History (7)

@Tkama
20 months ago

#1 @SergeyBiryukov
20 months ago

  • Component changed from General to I18N
  • Version changed from 6.2.2 to 4.4

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

#2 @swissspidy
3 months ago

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

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


3 months 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.


3 months 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
2 months ago

  • Resolution set to fixed
  • Status changed from reviewing to 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.