Feature: Translator return null for missing translations
Open
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 26
- Forks
- 10
- Avg merge
- 48m
- Merged PRs (30d)
- 1
Description
What steps will reproduce the problem?
Use Translator on not-existed key.
echo $translator->translate('not.existed.key'); // "not.existed.key"
What is the expected result?
I want to decide when translate() should return key or null.
$translationsForFooCategory = [
'label.some.existed.key' => 'Hello!',
];
$someOutput = $translator->translate('label.some.existed.key', category: 'foo');
$someOutput .= $translator->translate('description.some.not.existed.key', category: 'foo');
echo $someOutput; // "Hello!"
Throwing exception on missing translations is to complicated here.
I want to decide if given translate category return null on missing key or given TranlateInterface instance.
Additional info
| Q | A |
|---|---|
| Version | 3.0.0 |
| PHP version | 8.0 |
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Translator::translate() entry point and the TranslateInterface reference in the issue. Define the missing-key behavior and selection API, then add coverage for the shown existing and missing-key cases; done means callers can choose between the key and null without exceptions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- internationalization, localization
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100