Conversation
This change allows to access resources outside the composition while also allowing configuring ResourceEnvironment.
|
Could you file an issue for that? |
|
I understand a general idea to override resources' environment, but we have a consensus it should be done globally in the app. Moreover, the proposed API opens only a small specific sub-set of non-compose API to read custom strings. |
|
I updated the PR details. What do you think about it? |
|
I have a few concerns about the changes:
NB: Compose Web apps are single page apps, for now. I didn't research SSR or other scenarios. So, I couldn't value these changes, might be. In your specific case I'd recommend to use original xml resources on the backend to render your htmls. |
Problem
Currently,
StringResources.getString(...)andResourceEnvironmentare 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 aResourceEnvironmentmanually.Proposed Changes
ResourceEnvironment
language,region,theme,densitynow publicvals).copy(...)helper to allow modification without exposing adata class.StringResources
getString(...)that accept aResourceReaderparameter (default:DefaultResourceReader).Motivation
ResourceEnvironmentis crucial for generating pages in multiple locales programmatically.Open Questions
getStringsignatures 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.