Skip to content

KohaRest: add support for translation prefix#4787

Open
rajaro wants to merge 7 commits intovufind-org:devfrom
rajaro:koharest-translation-prefix
Open

KohaRest: add support for translation prefix#4787
rajaro wants to merge 7 commits intovufind-org:devfrom
rajaro:koharest-translation-prefix

Conversation

@rajaro
Copy link
Contributor

@rajaro rajaro commented Oct 29, 2025

No description provided.

Copy link
Member

@demiankatz demiankatz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @rajaro, this is a good idea. However, it seems to only be implemented for holds errors at present, and there are other places where it might also apply (storage retrieval requests, for example, or things like availability status messages). Should the scope be broadened before this is merged?

@rajaro rajaro requested a review from demiankatz November 5, 2025 11:13
Copy link
Member

@demiankatz demiankatz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @rajaro -- I think this could be made a little more readable with the help of a support method; see below for more details.

Copy link
Member

@demiankatz demiankatz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the progress, @rajaro, this is a lot more readable now!

See below for one minor suggested optimization, and a couple of questions about the application. I'm not at all familiar with Koha, so maybe my questions are misinformed -- I'm just asking based on a naive interpretation of what I see. Maybe @EreMaijala could offer a better-informed perspective on this.

);
if ($result['code'] >= 300) {
$msg = empty($result['data']['error'])
? $result['code']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also consider prefixing the code? I'm not sure what this value is going to look like, but maybe translating it (possibly in combination with a contextualizing prefix) would have some value. Sending an out-of-context number as the error message doesn't seem like it would be helpful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, added prefix to result code as well

return $this->itemStatusMappings[$statusKey]
?? $data['code'] ?? str_replace(':', '_', $statusKey);
?? $data['code']
?? $this->getPrefixedMessage(str_replace(':', '_', $statusKey));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know the code well enough to fully understand what's going on here, but this seems like it might potentially be problematic (how do item status mappings interact with translation prefixes? Why is code prioritized over status keys?). Just want to be sure that we don't have two conflicting mechanisms in play, and that we apply rules consistently.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea was to leave already mapped statuses as is, and only add translation prefix to non-mapped statuses. I don't know why code is prioritized over status key here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe @EreMaijala can share some thoughts on this.

Copy link
Member

@demiankatz demiankatz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the progress, @rajaro. I'm nearing the end of what I feel confident reviewing (and I'm hoping @EreMaijala can lend us his wisdom on the rest), but I did spot one area where I think some simplification might be justified.

return [
'success' => false,
'error' => $result['data']['error'] ?? $result['code'],
'error' => $msg,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're going to prefix both the code and the error message, we don't really need the more complex $msg assignment above, and we can just do this:

Suggested change
'error' => $msg,
'error' => $this->getPrefixedMessage($result['data']['error'] ?? $result['code']),

return $this->itemStatusMappings[$statusKey]
?? $data['code'] ?? str_replace(':', '_', $statusKey);
?? $data['code']
?? $this->getPrefixedMessage(str_replace(':', '_', $statusKey));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe @EreMaijala can share some thoughts on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants