Giter Site home page Giter Site logo

denysvuika / preact-translate Goto Github PK

View Code? Open in Web Editor NEW
64.0 3.0 6.0 3.29 MB

Minimalistic translate (i18n) library for Preact

License: MIT License

JavaScript 12.31% CSS 0.88% TypeScript 86.82%
preact i18n translation typescript preact-components preact-x

preact-translate's People

Contributors

denysvuika avatar dependabot-preview[bot] avatar dependabot[bot] avatar mergify[bot] avatar mpriour avatar noahm avatar toniopelo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

preact-translate's Issues

Redundant fetch for the same language

Description

In this demo, you can see duplicated requests to en.json from the DevTool's Network panel.

Expected behavior

en.json should be fetch only once

Actual behavior

en.json is fetched twice

is there a way to ensure translations are serve side rendered?

a) love the library's simplicity
b) ran into some hiccups:

  1. All the translations flash from translation key -> translation on page load (while en.json is being fetched)
    e.g. "footer.contact" is rendered onto the screen, quickly followed by the translation (e.g. "Contact Us")

  2. SSR is not rendering the translation
    e.g. in the page source code I literally see <a href="/contact">footer.contact</a>

if #2 could be fixed, then it would fix #1 for most cases.

any recommendations or thoughts on โ˜๏ธ ??

Setup unit testing

Configure unit testing.

Notes: for the time being there are some issues with PreactX RC and jest, needs investigation

Include translations in bundle

Include translations directly into the bundle

Advantages

  • Translations are immediately available after page load
  • similar approach as i18n
  • can be an optional feature

Downsides

  • increasing bundle size (especially in bigger projects)

In nested routes, JSON 404s

When using a nested route, the translation library looks for the JSON relative to the route rather than at the root of the project.

So when on a page that is generated by: <Route path="/trick/:id" component={Trick} />, the url is something like:
http://localhost:3000/trick/3 but the translate library looks for the localization JSON in http://localhost:3000/trick/assets/en.json rather than at the root http://localhost:3000/assets/en.json and it 404s.

Any suggestions on how to use this library on custom routes?

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.