• Resolved docbt

    (@docbt)


    Hi guys!

    I installed Polylang and could translate nearly everthing with po files and polylang string translations, except of one thing

    ‘%s ago’ is showing the day/month always in english.

    I couldn′t find an option to translate day, month and year… ‘ago’ gets translated.

    Where do I change this? All my other posts/sites show the time correctly. It has to be a missing translation of wpforo

    Tanks in advance!

Viewing 1 replies (of 1 total)
  • Thread Starter docbt

    (@docbt)

    After investigating the problem, it seems that the wordpress function human_time_diff() in formatting.php doens′t return translated strings (although the _n() function is called).

    I tried to override the locale variable and added a text-domain, but that doesn′t help, so I ended up in translating it in my themes functions manually.

    add_filter('human_time_diff', 'new_human_time_diff', 10, 2);
    function new_human_time_diff($from, $to) {
    
        // remove filter to prevent the loop
        remove_filter('human_time_diff', 'new_human_time_diff');
    
        $locale = get_locale();
    
        $timediff = human_time_diff($from, $to);
        if($locale == "en_US"){
            return $timediff;
         } else {
            $translate_from_plural = array("seconds", "mins", "days", "hours", "months", "weeks", "years");
            $translate_from_singular = array("second", "min", "day", "hour", "month", "week", "year");
            If ($locale == "de_DE"){
                $translate_to_plural = array("Sekunden", "Minuten", "Tagen", "Stunden", "Monaten", "Wochen", "Jahren");
                $translate_to_singluar = array("Sekunde", "Minute", "Tag", "Stunde", "Monat", "Woche", "Jahr");
            } elseif ($locale == "ja"){
                $translate_to_plural = array("秒", "分", "日々", "時間", "月", "週", "年");
                $translate_to_singluar = array("秒", "分", "日", "時間", "月", "週間", "年");
            }
            $timediff = str_replace($translate_from_singular,$translate_to_singluar,str_replace($translate_from_plural, $translate_to_plural, $timediff));
        
        }
        // restore the filter
        add_filter( 'human_time_diff', 'new_human_time_diff', 10, 2);     
    
        return $timediff;
    }
Viewing 1 replies (of 1 total)
  • The topic ‘Polylang missing date time translation’ is closed to new replies.