[Feature Request] Provide localized builds in the NPM distribution
See original GitHub issueThere is currently no easy way to add a couple of CDNs for several languages of the UI, then load the correct UI based on a parameter.
The page is in a certain language, how to make sure the correct UI gets used even after the user chooses a different language?
My suggestion is to make it so, the UI with the language can be chosen like so after adding those languages as CDN:
var uiJA = new firebaseui.ja.auth.AuthUI(firebase.auth());
var uiEN = new firebaseui.en.auth.AuthUI(firebase.auth());
or even firebaseui_ja
or something.
Now, no matter how many different CDNs with languages, they all point to the same variable: firebaseui
so it’s difficult to change that after the user switches languages. (especially talking about SPA’s with vueJS)
Issue Analytics
- State:
- Created 6 years ago
- Reactions:13
- Comments:12 (8 by maintainers)
Top Results From Across the Web
contentful - npm
JavaScript library for the Contentful Content Delivery API and Content Preview API. It helps you to easily access your Content stored in ...
Read more >Workspace npm dependencies - Angular
Alternatively, you can use the yarn client for downloading and installing npm packages. See Local Environment Setup for information about the required versions ......
Read more >Content Delivery API | Contentful
If you provide an invalid property path, e.g fields.doesNotExist , Contentful returns a 400 Bad request containing the invalid property path. Query entries....
Read more >End-to-End Multibranch Pipeline Project Creation - Jenkins
That is, the branch being built determines which delivery stage of your Pipeline is executed. ... 11, Allow local checkout for the tutorial....
Read more >Shadow CLJS User's Guide
The shadow-cljs npm package which provides a convenient interface for running most of the build functionality directly from command line.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I would use lazy-loading of the library. Your app will be too big and it is not good for performance to include all languages in the same bundle.
So you could still use a URL parameter or a has fragment, for instance let say you load
https://www.example.com/auth?lang=en
your code can be:
This is using Webpack’s dynamic import feature. The different localised versions of Firebase will be generated in different chunks that will be loaded on the fly when requested.
As you can see above the library is loaded asynchroneously so you’ll get firebaseui in a Promise. it gets nice though if you use async/await:
btw @bojeil-google, it would be cool to provide all the localised JS files in the NPM distrib so taht developers could do that easily.
Oh dear. Looks like you’ve used the wrong implementation architecture to support i18n for SPA web apps!
Except that we’re all coding SPA web apps today so we don’t reload pages from the server just one static page index.html and our client side “pages” are not server side rendered (remember: Firebase hosting is for static pages!) So making a Firebase UI build per language is inherently broken.
More commonly we wish to provide a feature in our SPA app to allow the user to change their language, dynamically. We expect that we can call a
firebaseui.setLanguage()
function that will lazy load a small JSON file to import the language changes. You could provide afirebaseui.getLocale()
which inspectswindow.navigator.languages
and map the browser locale to a matching FirebaseUI locale. If implemented this way, Firebase UI can just work by auto selecting the language.Workarounds …
Okay so I can kinda patch this up by inspecting
window.navigator.languages
, then creating a mapping function to convert real browser locales to the different ones provided by Firebase UI and do a dynamic load from the CDN of the language specific build.I now need to build just RTL and non-RTL versions of my index.html file since I cannot (currently) dynamically load CSS files with webpack.
Reference
Postlude
I’ve now had a closer look at how you’re doing i18n and I see that you’re using Angular’s 18n that forces you to do per language SDK builds. I still think you need a way to lazy loading the language build based on browser locale. My SPA framework assists with this restriction so i can workaround this.