Make ResourceEnvironment public #5425
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Currently,
StringResources.getString(...)
andResourceEnvironment
are only convenient to use inside a composition. For server-side rendering (SSR) with Kotlin/WasmJS, we need to serve html pages that are SEO-friendly and localized. This requires access to string resources outside composition and the ability to configure aResourceEnvironment
manually.Proposed Changes
ResourceEnvironment
language
,region
,theme
,density
now publicval
s).copy(...)
helper to allow modification without exposing adata class
.StringResources
getString(...)
that accept aResourceReader
parameter (default:DefaultResourceReader
).Motivation
ResourceEnvironment
is crucial for generating pages in multiple locales programmatically.Open Questions
getString
signatures to avoid breaking precompiled binaries?This change allows to access resources outside the composition while also allowing configuring ResourceEnvironment.The reason behind this change is to simplify the generation of SSR pages for Kotlin/WasmJs while also respecting localization.