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

Add getLocale() method #242

Merged
merged 5 commits into from
Nov 20, 2023
Merged

Add getLocale() method #242

merged 5 commits into from
Nov 20, 2023

Conversation

Tigrov
Copy link
Member

@Tigrov Tigrov commented Oct 27, 2023

It needs to get current locale when page is rendering

<html lang="<?= Html::encode($view->getLocale()) ?>">

Also this will allow fix issue yiisoft/app#290

Q A
Is bugfix?
New feature?
Breaks BC?
Fixed issues -

@what-the-diff
Copy link

what-the-diff bot commented Oct 27, 2023

PR Summary

  • Introduction of New Method in ViewTrait File
    A new function called 'getLocale()' has been added to the 'ViewTrait.php' file. This function is designed to provide the locale code, helping to identify the regional setting currently applied.

  • Addition of New Test in ViewTest File
    A fresh test named 'testGetLocale()' has been implemented into the 'ViewTest.php' file. This test focuses on evaluating the performance and behavior of the new 'getLocale()' method to ensure it works as expected.

@codecov
Copy link

codecov bot commented Oct 27, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (38e7351) 99.74% compared to head (3daa0ff) 99.74%.
Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##             master     #242   +/-   ##
=========================================
  Coverage     99.74%   99.74%           
- Complexity      302      303    +1     
=========================================
  Files            18       18           
  Lines           796      798    +2     
=========================================
+ Hits            794      796    +2     
  Misses            2        2           
Files Coverage Δ
src/State/WebViewState.php 100.00% <ø> (ø)
src/ViewTrait.php 100.00% <100.00%> (ø)
src/WebView.php 100.00% <ø> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

*/
public function getLocale(): string
{
return $this->localeState->getLocale();
Copy link
Member

Choose a reason for hiding this comment

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

Where's localeState?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good question.

It is inside View and WebView

view/src/WebView.php

Lines 39 to 45 in 9547650

final class WebView implements ViewInterface
{
use ViewTrait;
private WebViewState $state;
private LocaleState $localeState;

And state also

view/src/ViewTrait.php

Lines 228 to 231 in 9547650

public function getTheme(): ?Theme
{
return $this->state->getTheme();
}

This task for a new issue.

Copy link
Member

@vjik vjik Nov 10, 2023

Choose a reason for hiding this comment

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

This task for a new issue.

What is task?

ViewTrait is internal trait that used in View and WebView only.

Copy link
Member Author

Choose a reason for hiding this comment

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

This task for a new issue.

What is task?

ViewTrait is internal trait that used in View and WebView only.

Move localeState and state inside ViewTrait

CHANGELOG.md Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
src/ViewTrait.php Show resolved Hide resolved
Co-authored-by: Sergei Predvoditelev <sergei@predvoditelev.ru>
@vjik vjik added the status:under development Someone is working on a pull request. label Nov 10, 2023
@vjik vjik added this to the 9.0 milestone Nov 12, 2023
@vjik vjik added status:ready for merge The pull request is OK to be merged. and removed status:under development Someone is working on a pull request. labels Nov 12, 2023
@samdark samdark merged commit 3431ea8 into master Nov 20, 2023
@samdark samdark deleted the add-getlocale-method branch November 20, 2023 10:51
@samdark
Copy link
Member

samdark commented Nov 20, 2023

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:ready for merge The pull request is OK to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants