Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

[Localization]: Fix ViewLocalizer so it works for layouts too #2767

Closed
kirthik opened this issue Jun 30, 2015 · 6 comments
Closed

[Localization]: Fix ViewLocalizer so it works for layouts too #2767

kirthik opened this issue Jun 30, 2015 · 6 comments
Assignees
Milestone

Comments

@kirthik
Copy link
Contributor

kirthik commented Jun 30, 2015

ViewLocalizer cannot be used on layout pages since the logic in Contextualize method reads current view to get the resources file. Since ViewContext.View property does not point to layout, layout specific resources are not localized. Today we have to use IStringLocalizer for this scenario.

We should come up with a solution where ViewLocalizer works for layouts too.

@danroth27
Copy link
Member

@DamianEdwards

@danroth27 danroth27 added this to the 6.0.0-beta7 milestone Jun 30, 2015
@danroth27 danroth27 modified the milestones: 6.0.0-beta7, 6.0.0-beta6 Jul 2, 2015
@danroth27 danroth27 modified the milestones: 6.0.0-beta6, 6.0.0-beta7 Jul 15, 2015
@Eilon Eilon modified the milestones: 6.0.0-beta7, 6.0.0-beta8 Aug 7, 2015
@Eilon
Copy link
Member

Eilon commented Sep 2, 2015

@DamianEdwards do we want this for beta8? If so, we need to discuss a design.

@Eilon Eilon modified the milestones: Backlog, 6.0.0-beta8 Sep 2, 2015
@dougbu
Copy link
Member

dougbu commented Nov 28, 2015

Hit this issue while experimenting. For the same reason, localization does not work as expected in _ViewStart.cshtml files e.g. when setting a default ViewData["Message"] value. This breaks componentization and means resources must be repeated for all top-level views.

Suggest ViewLocalizer line 101 should use viewContext.ExecutingFilePath and not the current viewContext.View.Path. The first changes much more frequently.

@Eilon Eilon modified the milestones: 6.0.0-rc2, Backlog Nov 28, 2015
@Eilon
Copy link
Member

Eilon commented Nov 28, 2015

Can you clarify? Do you mean that _ViewStart is picking up resources from the real view that's running? If so, I agree that's wrong.

@dougbu
Copy link
Member

dougbu commented Nov 29, 2015

_ViewStart [and _Layout] is picking up resources from the real view that's running?

Yes, that's what I and @kirthik meant. Fortunately one design (thinking of the Needs Design label) is a one-line fix.

@DamianEdwards
Copy link
Member

ViewLocalizer should use ViewContext.ExecutingFilePath when constructing the resource base name

dougbu added a commit that referenced this issue Dec 15, 2015
DamianEdwards added a commit that referenced this issue Dec 18, 2015
DamianEdwards added a commit that referenced this issue Dec 18, 2015
DamianEdwards added a commit that referenced this issue Dec 21, 2015
DamianEdwards added a commit that referenced this issue Dec 21, 2015
- Always prepend with application name and let underlying `IStringLocalizerFactory` do the name gymnastics
- Use ExecutingFilePath instead of view name
- Trim off the file extension (so your resource doesn't have to have ".cshtml" in its name)
- Improved doc comments
- Added tests to cover ViewLocalizer behavior
- #3718
- #2767
DamianEdwards added a commit that referenced this issue Dec 21, 2015
- Always prepend with application name and let underlying `IStringLocalizerFactory` do the name gymnastics
- Use ExecutingFilePath instead of view name
- Trim off the file extension (so your resource doesn't have to have ".cshtml" in its name)
- Improved doc comments
- Added tests to cover ViewLocalizer behavior
- #3718
- #2767
dougbu added a commit that referenced this issue Jan 4, 2016
…se name

- follow-up to #2767
- resources are now associated with specific page, not the `IView` when the `ViewContext` was created

nit: remove unused `Resources` class
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants