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

hf-i18n

v0.1.8

Published

yarn add hf-i18n

Downloads

3

Readme

install

yarn add hf-i18n

component

<Language>

features

  • support 中/英 切換
  • support 切換語言的按鈕。
  • support i18n init

API

  • i18nInit function(languageList)
    • languageList 參數: 資料型態:物件,其為語言檔的 path。語言的縮寫必須依照 i18n 的規範。
  • Language 元件: API 無。

CSS

  • language 的 font-size 使用 em 為單位,可在 language 外層設定 font-size。或改變.language-btn-wrap font-size 的屬性。
  • .language-btn-wrap : 整個外包一層。
  • .language-btn-wrap .submenu button : 下拉式選單的按鈕的 style
  • .language-btn-wrap .submenu : 下拉式選單的 style
  • .language-btn-wrap::after : 可設定 display:none 來隱藏垂直的分隔線。

使用方法

  • 需要在 app 的進入點,index.js 中 import i18nInit,執行 i18nInit 函數,初始化 i18n。
  • 在你的 header 中呼叫元件 Language。

Demo

//App.js
import React from "react";
import { Translation } from "react-i18next";
import { Language } from "./hfi18n";
import i18n from "i18next";

class App extends React.Component {
  componentDidMount() {
    i18n.on("languageChanged", function(lng) {
      //當changeLanguage被呼叫。
      console.log(lng); //可以在這裡增加語言改變時的行為。
    });
  }
  render() {
    return (
      <div className="App">
        <Language />
        <Translation>{t => <p>{t("homePage.home")}</p>}</Translation>
      </div>
    );
  }
}

export default App;

//index.js(App的進入點)
import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
import App from "./App";
import * as serviceWorker from "./serviceWorker";
import { i18nInit } from "./hfi18n"; //呼叫i18nInit
import en from "./locales/en.json"; //英文的語言檔
import zhTW from "./locales/zhTW.json"; //繁體的語言檔

i18nInit({ en, zhTW }); //初始化i18n
ReactDOM.render(<App />, document.getElementById("root"));

// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: https://bit.ly/CRA-PWA
serviceWorker.unregister();