npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

better-i18n-for-svelte

v0.4.1

Published

SEO focused library for multi-language SvelteKit sites.

Downloads

10

Readme

Better I18N for Svelte

SEO focused library for multi-language SvelteKit sites.

Core features:

  • In-place editing of i18n messages via web brower in development mode.
  • I18n messages automatically stored in i18n.json files next to +page.svelte in your GIT repository.
  • SSR optimized. Production build contains real messages in HTML (no JS required to render).

These features are provided by the <I18n> component.

Advanced SEO features:

  • Localized URLs without having to duplicate the page's HTML structure.
  • Sets the HTML page title and meta description.
  • Adds <link rel="alternate" hreflang="lang"...> elements to pages to tell search engines about language variants.

These features are provided by the <I18nPage> component.

Try it

Run locally with npm run dev or try it on StackBlitz.

First steps: Open http://localhost:5173/en/simple/ and modify the h1 element in the web browser. You'll notice that the content of src/routes/en/simple/i18n.json file got updated. This way you can manage and review your i18n easily.

In-Place edit demo

The website of https://versiobit.com was built using this library. Switch from english to german in the footer. If you inspect the source HTML you see all i18n messages are embedded as raw strings and SEO friendly meta and link-alternate tags are present.

Roadmap

This library is in an early development stage and has some rough edges. Feedback is very welcome! Create an issue or comment on Reddit.

Documentaton

Setup for new projects

  • npm install better-i18n-for-svelte
  • copy the files in src/routes into your project as a starting point, replacing '$lib/..' in the imports with 'better-i18n-for-svelte'.

<I18n> component

This is the core component. Place it into a svelte component and it will insert the given I18n message, e.g.

<h1><I18n name="title"/></h1>

When running in dev mode, you can modify the message by clicking on the element in the web browser.

Notes:

  • the language information is taken from the page path (e.g. /en/simple).
  • if you have many pages you can use SvelteKits route parameter feature, e.g. create a folder like src/routes/[lang]/simple/

<I18nPage> component

This component provides a more opinionated way of how to build a multi language site.

If a page should exist in multi languages, create the folders and +page.svelte files as you normally would, e.g. /en/about-us for the English variant and /de/ueber-uns for the German variant.

Create a shared about.svelte component (e.g. in src/routes/en/about-us/about.svelte) that can be re-used by each variant like this:

<I18nPage id="/en/about-us">
	<h1><I18n name="title" /></h1>
	<p><I18n name="description" /></p>
</I18nPage>

The id should be the directory path of this component within 'src/routes'. Thus, the id stays the same for each language variant of the page.

Customization

You can pass defaults in the call to initI18nContext. For example, to change the default language do:

initI18nContext(serverI18nData, {defaultLanguage: 'de'});	

Development

Local

npm install
npm run dev

Publishing

To build/publish use:

npm run package
npm publish