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

i18next-mobx

v0.0.1

Published

A management scheme for i18nxet mobx

Downloads

4

Readme

i18next-mobx

i18next mobx状态管理方案
通过 mobx 去代理管理 i18next

你的程序 如果是采用 Mobx 来做 状态管理 那么 用 i18next-mobx 来实现国际化就是不错的选择

release candidate  i18next Version  Mobx Version  GitHub license 

Demo

React Demo

下载

npm i i18next-mobx 或 yarn add i18next-mobx

引入与使用

使用方式,配置和插件扩展等 基本与 i18next 保持一致, 详情配置可点击前往i18next官网查看

import i18NextMobx from "i18next-mobx";

i18NextMobx.init({
  lng: 'zh-CN',
  debug: true,
  resources: {
    en: {
      translation: {
        "key": "hello world"
      }
    }
  }
});
//已初始化并准备就绪!
//i18nMobx已经初始化,因为转换资源是通过init函数传递的
document.getElementById('output').innerHTML = i18nMobx.t('key');

使用扩展插件

import i18NextMobx from "i18next-mobx";
import { initReactI18next } from "react-i18next"
import LanguageDetector from "i18next-browser-languagedetector"

i18NextMobx
 .use(LanguageDetector)
 .use(initReactI18next)
 .init({
  lng: 'zh-CN',
  debug: true,
  resources: {
    en: {
      translation: {
        "key": "hello world"
      }
    }
  }
});
//已初始化并准备就绪!
//i18nMobx已经初始化,因为转换资源是通过init函数传递的
document.getElementById('output').innerHTML = i18nMobx.t('key');

组件中使用

函数式组件

✨(推荐使用)引入 i18next-mobx 后的使用方法

import { t } from 'i18next-mobx';

export const MyComponent = observer(function () {
  return <p>{t('my translated text')}</p>
})

同时也兼容已有Hooks 方案

import { useTranslation } from 'react-i18next';

export const MyComponent = function() {
  const { t, i18n } = useTranslation();
  // or const [t, i18n] = useTranslation();
  return <p>{t('my translated text')}</p>
}

Class(类)组件

✨(推荐使用)引入 i18next-mobx 后的使用方法

import React from 'react';
import {observer} from "mobx-react";
import { t } from 'i18next-mobx';

@observer
export class MyComponent extends React.Component {
    render() {
        return (<p>{t('my translated text')}</p>)
    }
};

同时也兼容已有的Hoc方案

import React from 'react';
import { withTranslation } from 'react-i18next';

class MyComponent extends React.Component {

  render() {
	const { t } = this.props;
	return (<p>{t('my translated text')}</p>);
  }
}

export default withTranslation()(MyComponent);