Git Product home page Git Product logo

Comments (8)

NetanelBasal avatar NetanelBasal commented on May 21, 2024 4

@DmitryEfimenko I rewrote it from scratch, the new implementation will be:

export function getLangFn({ cachedLang, browserLang, cultureLang, defaultLang }) {
  return whatYouWant;
}

@NgModule({
  imports: [
    TranslocoPersistLangModule.init({
      getLangFn,
      storage: {
        provide: TRANSLOCO_PERSIST_LANG_STROAGE,
        useValue: localStorage
      },
    })
  ],
})
class AppModule {}

We'll also expose the cookieStorage. If you don't provide a getLangFn function it will take cachedLang || defaultLang.

from transloco.

itayod avatar itayod commented on May 21, 2024 3

Hey @DmitryEfimenko,
After reconsidering this feature, we have decided not to implement it as part of the library, as we try to keep it as clean and simple as possible.

Also implementing this feature is pretty easy and doesn't require a lot of code:

  constructor(private transloco: TranslocoService) {}

  ngOnInit() {
    // set the saved language from local storage.
    this.transloco.setActiveLang(localStorage.getItem('lang'));

    // persist the current language in local storage.
    this.transloco.langChanges$.pipe(distinctUntilChanged())
        .subscribe(lang => localStorage.setItem('lang', lang));
  }

Does it satisfy your issue?

from transloco.

shaharkazaz avatar shaharkazaz commented on May 21, 2024 2

@DmitryEfimenko It's on its way 🙂
we are planning to start work next week.

from transloco.

shaharkazaz avatar shaharkazaz commented on May 21, 2024 1

@agugan Hey, we are working on something and a PR should be ready soon, you are welcome to track this 🙂

from transloco.

NetanelBasal avatar NetanelBasal commented on May 21, 2024 1

@DmitryEfimenko could you check if the following PR resolved this issue, please?

https://github.com/ngneat/transloco/pull/34/files

Feel free to suggest changes based on your experience and needs.

from transloco.

agugan avatar agugan commented on May 21, 2024

@shaharkazaz
I am not sure whether this is incorporated in the planning or already exists. But I would also like to add a sub feature to it.

Our enterprise applications have multiple sub-projects to switch between. Sometimes we have language selection coming in from different source than the rest of project.

Currently we have to store the selected language in cookie/LS and retrieve it the respective translation module initialization.

Future: I would like to see it integrated to translation store itself.
Ex:

{
      provide: TRANSLOCO_CONFIG,
      useValue: {
        prodMode: environment.production,
        listenToLangChange: true,
        defaultLang: 'en',
        persistLanguage: {  
         persistLanguageAcross: true,
         name: 'selected_lanaguage_transloco'
   }
      }
    }

So when these options enabled, we will store the selected language also in cookie/Local/Session storage under the given name, and then we can first check for the persisted language in sub-projects else fallback to defaultLanguage.

Though this look like a specific usecase, but its also one of the bigger pain points in translations.
If you like this feature, I would love to submit a PR with help.

from transloco.

DmitryEfimenko avatar DmitryEfimenko commented on May 21, 2024

it's trivial to save it to the localStorage. It becomes more involved when saving it to the cookie which is a valid use-case if you want to have it working with SSR.

If worrying about the library size, make it a separate addon library just like in the case of ngx-translate-cache, which is separate from ngx-translate. It does not need to be a part of the transloco library itself.

As a matter of fact, a lot of the implementation could be straight copy-pasted from ngx-translate-cache.

from transloco.

DmitryEfimenko avatar DmitryEfimenko commented on May 21, 2024

That looks clean!

from transloco.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.