Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEAT support variables as second and third argument #11521

Merged
merged 13 commits into from
Jan 27, 2025

Conversation

lekoala
Copy link
Contributor

@lekoala lekoala commented Dec 30, 2024

Description

This PR upgrades the text collector to support collecting arguments as variables for second and third argument (see examples below).

Manual testing steps

        // Should display last $str and support concatenation
        $str = 'Should NOT appear';
        $str = 'Lazy loading can increase perceived page performance by slightly delaying media loading. ' .
            'Eager loading will load files as soon as possible and can be used if the image is in view as the page ' .
            'loads (above or near the fold).';
        $titleTipContent = _t('DemoAdmin.LoadingTitleTip', $str);

        // Does not support variables, use {type}. This will improperly detect "test" as value for the translation
        $type = "test";
        $IDontHaveAValidSyntax = _t(__CLASS__ . '.CANNOT_DELETE', "Not allowed to delete '$type' records");

        // Support variable as third argument
        $var = ['some' => 'var'];
        $IWasNotCollected = _t('DemoAdmin.ImNOTCollected', 'test {some}', $var);

        // Support default case
        $ImCollected = _t('DemoAdmin.ImCollected', 'test {some}', ['some' => 'var']);

Issues

Pull request checklist

  • The target branch is correct
  • All commits are relevant to the purpose of the PR (e.g. no debug statements, unrelated refactoring, or arbitrary linting)
    • Small amounts of additional linting are usually okay, but if it makes it hard to concentrate on the relevant changes, ask for the unrelated changes to be reverted, and submitted as a separate PR.
  • The commit messages follow our commit message guidelines
  • The PR follows our contribution guidelines
  • Code changes follow our coding conventions
  • This change is covered with tests (or tests aren't necessary for this change)
  • Any relevant User Help/Developer documentation is updated; for impactful changes, information is added to the changelog for the intended release
  • CI is green

@GuySartorelli
Copy link
Member

Please fill in the PR checklist. That checklist is there to help you as the contributor double check you've done everything you need to do. That means that I as the reviewer will then know whether you have done those things which speeds things up a little.

Copy link
Member

@GuySartorelli GuySartorelli left a comment

Choose a reason for hiding this comment

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

Most of this review is just me asking for clarification, since I haven't worked in this part of the code much before so I need a bit of help understanding what's going on.

src/i18n/TextCollection/i18nTextCollector.php Outdated Show resolved Hide resolved
src/i18n/TextCollection/i18nTextCollector.php Outdated Show resolved Hide resolved
src/i18n/TextCollection/i18nTextCollector.php Outdated Show resolved Hide resolved
src/i18n/TextCollection/i18nTextCollector.php Outdated Show resolved Hide resolved
src/i18n/TextCollection/i18nTextCollector.php Outdated Show resolved Hide resolved
src/i18n/TextCollection/i18nTextCollector.php Outdated Show resolved Hide resolved
src/i18n/TextCollection/i18nTextCollector.php Show resolved Hide resolved
src/i18n/TextCollection/i18nTextCollector.php Outdated Show resolved Hide resolved
src/i18n/TextCollection/i18nTextCollector.php Outdated Show resolved Hide resolved
src/i18n/TextCollection/i18nTextCollector.php Outdated Show resolved Hide resolved
@GuySartorelli
Copy link
Member

Please retarget this to the 5 branch - it's adding new functionality and has a risk of regression that I'd rather not introduce in a patch.

@lekoala
Copy link
Contributor Author

lekoala commented Jan 6, 2025

@GuySartorelli ideally i'd like to make sure there is no regression
currently, code like this silverstripe/silverstripe-asset-admin#1532 is not being collected so I assume it is considered "valid code" according to current features, no?

@GuySartorelli
Copy link
Member

Any change has some chance of regression. There's no known regressions this causes, but because it's code I'm unfamiliar with, there is a chance of regressions that I won't be able to identify.

Regardless, as this is adding new functionality, it is better included in a minor release rather than a patch release.

@lekoala lekoala changed the base branch from 5.3 to 5 January 9, 2025 16:43
@lekoala
Copy link
Contributor Author

lekoala commented Jan 9, 2025

ok rebased!

i don't know if any test or update is needed

a unit test would be nice but i didn't go as far as that. i've just tried locally on my project and it seemed to work fine

@GuySartorelli
Copy link
Member

I won't have time to test this out myself until at least halfway through next week.
Unit tests would be great if you have time to implement them.

@lekoala
Copy link
Contributor Author

lekoala commented Jan 10, 2025

@GuySartorelli i added the tests and improved how i track strings. i added some comments to make it more clear how it works. the whole test suite is running fine locally

src/i18n/TextCollection/i18nTextCollector.php Outdated Show resolved Hide resolved
src/i18n/TextCollection/i18nTextCollector.php Outdated Show resolved Hide resolved
src/i18n/TextCollection/i18nTextCollector.php Outdated Show resolved Hide resolved
src/i18n/TextCollection/i18nTextCollector.php Show resolved Hide resolved
src/i18n/TextCollection/i18nTextCollector.php Outdated Show resolved Hide resolved
src/i18n/TextCollection/i18nTextCollector.php Outdated Show resolved Hide resolved
src/i18n/TextCollection/i18nTextCollector.php Outdated Show resolved Hide resolved
src/i18n/TextCollection/i18nTextCollector.php Outdated Show resolved Hide resolved
@lekoala
Copy link
Contributor Author

lekoala commented Jan 17, 2025

@GuySartorelli updated the code and added test cases for falsy values and $x = 'test' ; $x .= 'more';

Copy link
Member

@GuySartorelli GuySartorelli left a comment

Choose a reason for hiding this comment

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

Looks good, great unit test. Thank you!

@GuySartorelli GuySartorelli merged commit 31e5e4f into silverstripe:5 Jan 27, 2025
17 checks passed
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