hebcal / dotcom

deprecated hebcal.com source code
https://github.com/hebcal/hebcal-web
21 stars 9 forks source link

Using lg sh or ah with rest api doesn't translate title to hebrew #38

Open roidayan opened 4 years ago

roidayan commented 4 years ago

When using lg=ah or lg=sh the title is not translated into hebrew. When using lg=h its fine.

the issue is maybe from line 753 in local/share/perl/site_perl/Hebcal.pm https://github.com/hebcal/dotcom/blob/master/local/share/perl/site_perl/Hebcal.pm the check is only for "h"

    if ($lang eq "h" || $lang_european{$lang}) {
        my $xsubj = Hebcal::translate_event($evt, $lang);
        if ($xsubj && $xsubj ne $subj) {
            $item{title_orig} = $subj;
            $subj = $xsubj;
        }
    }

looking in translate_event() the check is also for "ah" and "sh"

    } elsif ($lang eq "h" || $lang eq "ah" || $lang eq "sh") {
        return $evt->{hebrew};
mjradwin commented 4 years ago

I believe the API always returns Hebrew as a separate field - so you should use lg=s or lg=a only. lg=ah and lg=sh are designed for the HTML website, not for the API.

On Sat, Oct 12, 2019 at 10:34 AM Roi Dayan notifications@github.com wrote:

When I use lg=ah or lg=sh. i dont get the title translate into hebrew. When using lg=h its fine.

the issue is maybe from line 753 in local/share/perl/site_perl/Hebcal.pm the check is only for "h"

if ($lang eq "h" || $lang_european{$lang}) {
    my $xsubj = Hebcal::translate_event($evt, $lang);
    if ($xsubj && $xsubj ne $subj) {
        $item{title_orig} = $subj;
        $subj = $xsubj;
    }
}

looking in translate_event() the check is also for "ah" and "sh"

} elsif ($lang eq "h" || $lang eq "ah" || $lang eq "sh") {
    return $evt->{hebrew};

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/hebcal/dotcom/issues/38?email_source=notifications&email_token=AA4YFVMHOYVHLZJ33BCBML3QOIDEDA5CNFSM4JADXA5KYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HRMHPEQ, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA4YFVLSRRI3CQUQCIF72DLQOIDEDANCNFSM4JADXA5A .

roidayan commented 4 years ago

right. just the hebrew key and title key sometimes little different. since 'h' is documented in the rest api i thought to use it. example for candle lighting and havdalah it adds the time already to the title. i'll use lg=s and parse the time manually and use hebrew key. thanks.

        [1] => Array
            (
                [title] => הדלקת נרות: 17:53
                [hebrew] => הדלקת נרות
                [title_orig] => Candle lighting
                [date] => 2019-10-13T17:53:00+03:00
                [category] => candles
            )
        [10] => Array
            (
                [title] => הבדלה - 50 דקות: 18:54
                [hebrew] => הבדלה - 50 דקות
                [title_orig] => Havdalah (50 min)
                [date] => 2019-10-19T18:54:00+03:00
                [category] => havdalah
            )
roidayan commented 4 years ago

I was rethinking. it should work. like fr should translate to france. options 'h', 'ah', 'sh' documented as supported in the rest api.

looks like the issue is just checking lang eq 'h' only, while the inner callback does check every option possible. I think maybe the first check is redundant and line 753 can be removed. calling translate_event() is doing the check and if nothing is needed returns undef which means title key wont be changed.

a user supposedly can send the lang according to "locale" like 'h' or 'fr' etc and always use key 'title'.