Add translation for stopped state notice#2337
Conversation
There was a problem hiding this comment.
Pull request overview
This PR plumbs the user-facing locale ($c->stash->{i18n}) from the Mojolicious frontend through the WebSocket list_machines/list_machines_tree handlers down into Ravada::Front::list_domains, so the duration element of date_status_change (e.g. ["5", "minutes"] / ["now", ""]) is translated. It also adds the corresponding entries in en/es/ca .po files (plus "Virtual Machine locked" / "Show lock details") and contains an unrelated tweak to t/lib/Test/Ravada.pm that switches some removal requests from user_admin to Ravada::Utils::user_daemon.
Changes:
- Pass
i18nfrom the Mojolicious stash throughRavada::WebSocket::_list_machinesintoRavada::Front::list_domains, where the new code localizes the count/unit pair underdate_status_change->{duration}. - Add translations for
minutes,year,month,week,day,hour,minute,now,Virtual Machine lockedandShow lock detailsinen.po,es.poandca.po. - Switch the user id used for
remove_base/remove_domainrequests in the test helper fromuser_admintouser_daemon(unrelated to the stated purpose).
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| script/rvd_front | Passes i18n => $c->stash->{i18n} when subscribing to the WebSocket. |
| lib/Ravada/WebSocket.pm | Requires i18n arg (via die) and forwards it as a filter to list_machines. |
| lib/Ravada/Front.pm | Extracts i18n from args and localizes the duration tuple returned by _date_status_change; second branch lacks a ref() guard. |
| lib/Ravada/I18N/en.po | New msgid/msgstr entries for time units and lock notices. |
| lib/Ravada/I18N/es.po | Spanish translations for the new entries. |
| lib/Ravada/I18N/ca.po | Catalan translations for the new entries. |
| t/lib/Test/Ravada.pm | Switches removal requests in remove_domain_and_clones_req from user_admin to user_daemon (unrelated to PR purpose). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| sub _list_machines($rvd, $args) { | ||
| my $login = $args->{login} or die "Error: no login arg ".Dumper($args); | ||
| my $i18n = $args->{i18n} or die "Error: no i18n arg ".Dumper($args); |
| if (exists $row->{date_status_change}->{duration} | ||
| && ref($row->{date_status_change}->{duration}) | ||
| && $row->{date_status_change}->{duration}->[0] =~ /^[a-z]+$/i | ||
| && defined $i18n && $row->{date_status_change}->{duration}->[0]) { | ||
| $row->{date_status_change}->{duration}->[0] = $i18n->localize($row->{date_status_change}->{duration}->[0]); | ||
| } | ||
| if (defined $i18n && $row->{date_status_change}->{duration}->[1]) { | ||
| $row->{date_status_change}->{duration}->[1] = $i18n->localize($row->{date_status_change}->{duration}->[1]); | ||
| } |
| $req_rm = Ravada::Request->remove_base( | ||
| uid => Ravada::Utils::user_daemon->id | ||
| ,id_domain => $domain->id) | ||
| if $domain->is_base; | ||
|
|
||
| my @after_req; | ||
| @after_req = ( after_request => $req_clone->id ) if $req_clone; | ||
| @after_req = ( after_request => $req_rm->id ) if $req_rm; | ||
| my $req= Ravada::Request->remove_domain( | ||
| name => $domain->name | ||
| ,uid => user_admin->id | ||
| ,uid => Ravada::Utils::user_daemon->id |
| , login => $USER->name | ||
| , remote_ip => _remote_ip($c) | ||
| , client => _headers($c) | ||
| , i18n => $c->stash->{i18n} |
| if (exists $row->{date_status_change}->{duration} | ||
| && ref($row->{date_status_change}->{duration}) | ||
| && $row->{date_status_change}->{duration}->[0] =~ /^[a-z]+$/i | ||
| && defined $i18n && $row->{date_status_change}->{duration}->[0]) { | ||
| $row->{date_status_change}->{duration}->[0] = $i18n->localize($row->{date_status_change}->{duration}->[0]); | ||
| } | ||
| if (defined $i18n && $row->{date_status_change}->{duration}->[1]) { | ||
| $row->{date_status_change}->{duration}->[1] = $i18n->localize($row->{date_status_change}->{duration}->[1]); | ||
| } |
Adds the translation for the notice that indicates since how many time has a machine been stopped.