Code Monkey home page Code Monkey logo

Comments (5)

comahe-de avatar comahe-de commented on August 25, 2024 1

Added the fix and a nodeJS test without browser which triggered the fix.

You may check the PR #50

from i18n4k.

trentkan avatar trentkan commented on August 25, 2024

Stack trace if helpful:

ReferenceError: window is not defined
ReferenceError: window is not defined
	at <global>._init_properties_Locale_kt__dhcc6y(~/i18n4k/i18n4k-core/src/jsMain/kotlin/de/comahe/i18n4k/Locale.kt:27)
	at <global>.get_systemLocale(kotlin/i18n4k-i18n4k-core.js:1831)
	at <global>.new I18n4kConfigDefault(~/i18n4k/i18n4k-core/src/commonMain/kotlin/de/comahe/i18n4k/config/I18n4kConfigDefault.kt:24)
	at <global>._init_properties_I18n4k_kt__k748j9(~/i18n4k/i18n4k-core/src/commonMain/kotlin/de/comahe/i18n4k/I18n4k.kt:7)
	at <global>.set_i18n4k(~/kotlin/i18n4k-i18n4k-core.js:208)
	at <global>.setLocale(src/commonMain/kotlin/Test.kt:22)

It seems like it has something to do with how the global object is set.

from i18n4k.

comahe-de avatar comahe-de commented on August 25, 2024

Hi @trentkan,
From you stack-trace I see that in this line from the Locale module, where systemLocale is defined, window is referenced: https://github.com/comahe-de/i18n4k/blob/master/i18n4k-core/src/jsMain/kotlin/de/comahe/i18n4k/Locale.kt#L27

And I18n4kConfigDefault references to systemLocale.

As the Locale class is essential, you cannot replace it.

I was not aware that window is not always available. I will make a try-catch around.

Meanwhile, you may try this workaround: https://stackoverflow.com/a/46908295/2611134
Using the "global"-lib: https://www.npmjs.com/package/global

from i18n4k.

trentkan avatar trentkan commented on August 25, 2024

Ah, I trace that now. So anytime I create a Locale in JS, it will reference window when it sets systemLocale...

That being said, can we follow a similar implementation as in Java - that is, to check for presence of window.navigator.language, otherwise fall back to default.

or perhaps just remove the concept of systemLocale and use english for localeRef consistency?

from i18n4k.

trentkan avatar trentkan commented on August 25, 2024

Thank you @comahe-de. I will check this out

from i18n4k.

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.