Skip to:
Content

BuddyPress.org

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#7275 closed defect (bug) (fixed)

bp_core_enqueue_livestamp() results can't be properly translated

Reported by: slaFFik Owned by: r-a-y
Milestone: 2.7 Priority: normal
Severity: normal Version:
Component: I18N Keywords: has-patch
Cc:

Description

bp_core_enqueue_livestamp() was introduced in 2.7. It has this array, which includes both singular and plurals:

array(
    'future' => __( 'in %s',         'buddypress' ),
    'past'   => __( '%s ago',        'buddypress' ),
    's'      => __( 'a few seconds', 'buddypress' ),
    'm'      => __( 'a minute',      'buddypress' ),
    'mm'     => __( '%d minutes',    'buddypress' ),
    'h'      => __( 'an hour',       'buddypress' ),
    'hh'     => __( '%d hours',      'buddypress' ),
    'd'      => __( 'a day',         'buddypress' ),
    'dd'     => __( '%d days',       'buddypress' ),
    'M'      => __( 'a month',       'buddypress' ),
    'MM'     => __( '%d months',     'buddypress' ),
    'y'      => __( 'a year',        'buddypress' ),
    'yy'     => __( '%d years',      'buddypress' ),
)

In Russian (and some other languages) plural like '%d years' can have 2 forms, for 2-4 (22-24 etc) items, and 5+ (25-30 etc). The word "years" in this case will be translated differently: "года" and "лет". Same for months/days/etc.

It seems we need to use _n() or translate_nooped_plural() with _n_noop().

Attachments (1)

7275.01.patch (390.6 KB) - added by r-a-y 3 years ago.

Download all attachments as: .zip

Change History (11)

@r-a-y
3 years ago

#1 @r-a-y
3 years ago

  • Keywords has-patch added

Attached is a patch that includes all of moment.js' locales as separate files and tries to dynamically load the right moment.js locale based on the current WordPress locale.

Warning: It's a large patch. Let me know if it applies cleanly.

This ticket was mentioned in Slack in #buddypress by r-a-y. View the logs.


3 years ago

This ticket was mentioned in Slack in #buddypress by djpaul. View the logs.


3 years ago

#4 @DJPaul
3 years ago

I don't think I have enough skill with this issue to meaningful contribute, but if we do add the javascript, we'll need to remember to check each release for updated upstream javascripts (something we ought to get in the habit of anyway -- maybe something for a beta checklist).

#5 @r-a-y
3 years ago

I don't think I have enough skill with this issue to meaningful contribute

@DJPaul - Thanks for looking.

Can still use your feedback on directory structure. I've placed the moment.js locales in /bp-core/js/vendor/moment-locales/, but perhaps you have a better suggestion?


we'll need to remember to check each release for updated upstream javascripts (something we ought to get in the habit of anyway -- maybe something for a beta checklist).

For sure.

This ticket was mentioned in Slack in #buddypress by r-a-y. View the logs.


3 years ago

This ticket was mentioned in Slack in #buddypress by mercime. View the logs.


3 years ago

#8 @r-a-y
3 years ago

In 11190:

Core: Update moment.js to v2.15.1.

We're also moving the file to the /vendor/moment-js/ directory, which
will be used to house all of the locale files for moment.js in a
subsequent commit.

See #7275.

#9 @r-a-y
3 years ago

  • Owner set to r-a-y
  • Resolution set to fixed
  • Status changed from new to closed

In 11191:

Core: Add moment.js locale files and load appropriate locale file if found.

This commit adds all the locale files for moment.js and tries to load
the appropriate locale file based off of the current WordPress locale.

This is so sites that do not use U.S. English will see the correct
localized version of moment.js.

Developers can filter 'bp_core_register_common_scripts' by checking the
'bp-moment-locale' array key to change the locale file if desired.

Props r-a-y, slaFFik.

Fixes #7275.

#10 @r-a-y
3 years ago

@slaFFik - Thanks for the feedback you gave in today's dev chat.

Regarding filtering the moment.js locale file, I decided not to introduce a new filter for this. Instead, you should be able to use the already, existing 'bp_core_register_commons_scripts' filter.

Here's a quick code snippet:

<?php
add_filter( 'bp_core_register_common_scripts', function( $retval ) {
    if ( isset( $retval['bp-moment-locale'] ) ) {
        $retval['bp-moment-locale']['file'] = 'hxxp://NEWLINK.com/moment-custom-locale.js';
    }
    return $retval;
} );

Let me know if you see anything else that needs addressing.

Note: See TracTickets for help on using tickets.