Force gettext to read default language

I have a loop in my WP-plugin that displays days.

For this, I do:

Read More
for ($day = 0; $day <= 4; $day++) {
   __('day'.$day,'textdomain')
}

In my pot-files, I have translated day0, day1 etc.

This works perfectly fine except for the default-language which is english. English is just showing “day0”.

Help!

Related posts

Leave a Reply

1 comment

  1. The behavior you are seeing is documented and expected, that is that the translations are keyed to the native language, not an arbitrary string. there are at least four ways to fix this three right ways and the interesting way. Here is both:

    Since you did not specify what language you are writing in I will assume perl.

    The right way #1

    my @day=(
    __x('Sun', 'textdomain'),
    __x('Mon', 'textdomain'),
    __x('Tue', 'textdomain'),
    __x('Wed', 'textdomain'),
    __x('Thu', 'textdomain'),
    __x('Fri', 'textdomain'),
    __x('Sat', 'textdomain')
    )
    for ($day = 0; $day <= 4; $day++) {
       __($day[$day],'textdomain')
    }
    

    The right way #2

    my @day=(
    __('Sun', 'textdomain'),
    __('Mon', 'textdomain'),
    __('Tue', 'textdomain'),
    __('Wed', 'textdomain'),
    __('Thu', 'textdomain'),
    __('Fri', 'textdomain'),
    __('Sat', 'textdomain')
    )
    for ($day = 0; $day <= 4; $day++) {
       $day[$day]
    }
    

    Both of these methods require updating all your translations.

    The right way #3

    Use date functions that are already localized.

    The interesting way

    if(__('day0', 'textdomain')eq'day0'){
        $ENV{LC_ALL}='en_US';
        setlocale(LC_ALL, 'en_US');
    }
    for ($day = 0; $day <= 4; $day++) {
       __('day.'$day,'textdomain')
    }