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

react-native-translator

v1.2.0

Published

Free translate component & hook

Downloads

347

Readme

React Native Translator

codecov CI Check availability npm version npm download License MIT Example Stars

Preview


Introduce

Unofficial free translate component & hook

Never need api key, This library is Unlimited free


Support translators


Getting started

First, Install package

yarn add react-native-translator react-native-webview

Second, Pod intsall

cd ios && pod install

Third, Add provider

// App.js
...
import {TranslatorProvider} from 'react-native-translator' // here

const App = () => {
  return (
    <TranslatorProvider> // here
        <.../>
    </TranslatorProvider> // here
  );
};

API

Translator ( Real-time translate )

// Usage
import Translator from 'react-native-translator';

const App = () => {
  const [value, setValue] = useState('');
  const [result, setResult] = useState('');

  return (
    <View>
      <Translator
        from="en"
        to="fr"
        value={value}
        onTranslated={(t) => setResult(t)}
      />
      <TextInput value={value} onChangeText={(t) => setValue(t)} />
      <Text>{result}</Text>
    </View>
  );
};

| Props | Type | Default value | Required | | ------------ | ---------------------------------- | ------------- | -------- | | from | LanguageCode | | ✅ | | to | LanguageCode | | ✅ | | value | string | | ✅ | | type | TranslatorType | 'google' | | | onTranslated | (result: string) => void | | ✅ |

useTranslator

// Usage
import {useTranslator} from 'react-native-translator';

const App = () => {
  const {translate} = useTranslator();

  const [value, setValue] = useState('');
  const [result, setResult] = useState('');

  const onTranslate = async () => {
    const _result = await translate('en', 'fr', value);
    setResult(_result);
  };

  return (
    <View>
      <TextInput value={value} onChangeText={(t) => setValue(t)} />
      <Text>{result}</Text>
      <Button title="translate" onPress={onTranslate} />
    </View>
  );
};

translate

// const {translate} = useTranslator();
type translate: <T extends TranslatorType>(/* check follow param table */) => Promise<string>;

| param | Type | Default value | Required | | ------ | ------------------------------------------------------------ | ------------------------------- | -------- | | from | LanguageCode | | ✅ | | to | LanguageCode | | ✅ | | value | string | | ✅ | | option | {type?: TranslatorType, timeout?: number} | {type: 'google', timeout: 5000} | |

languageCodeConverter

❗️ If conversion is not possible, return undefined.

import {languageCodeConverter} from 'react-native-translator';
// google language code convert to kakao language code
languageCodeConverter('google', 'kakao', 'ko'); // kr

TranslatorType

type TranslatorType = 'google' | 'kakao' | 'papago';

LanguageCode

type LanguageCode<T extends TranslatorType> ...
// Usage
type GoogleLanguageCode = LanguageCode<'google'>;

VALUES

import {LANGUAGE_CODES, TRANSLATOR_TYPES} from 'react-native-translator';
// translator types
TRANSLATOR_TYPES; // ["google", "papago", "kakao", ...]
// language code
LANGUAGE_CODES['google']; // ["af", "ga", "sq", ...]

Support languages

| Language | Google | Papago | Kakao | | ------------------- | ------ | ------ | ----- | | Afrikaans | af | | | | Irish | ga | | | | Albanian | sq | | | | Italian | it | it | it | | Arabic | ar | | ar | | Japanese | ja | ja | jp | | Azerbaijani | az | | | | Kannada | kn | | | | Basque | eu | | | | Korean | ko | ko | kr | | Bengali | bn | | bn | | Latin | la | | | | Belarusian | be | | | | Latvian | lv | | | | Bulgarian | bg | | | | Lithuanian | lt | | | | Catalan | ca | | | | Macedonian | mk | | | | Chinese Simplified | zh-CN | zh-CN | cn | | Malay | ms | | | | Chinese Traditional | zh-TW | zh-TW | cn | | Maltese | mt | | | | Croatian | hr | | | | Norwegian | no | | | | Czech | cs | | | | Persian | fa | | | | Danish | da | | | | Polish | pl | | | | Dutch | nl | | nl | | Portuguese | pt | | pt | | English | en | en | en | | Romanian | ro | | | | Esperanto | eo | | | | Russian | ru | ru | ru | | Estonian | et | | | | Serbian | sr | | | | Filipino | tl | | | | Slovak | sk | | | | Finnish | fi | | | | Slovenian | sl | | | | French | fr | fr | fr | | Spanish | es | es | es | | Galician | gl | | | | Swahili | sw | | | | Georgian | ka | | | | Swedish | sv | | | | German | de | de | de | | Tamil | ta | | | | Greek | el | | | | Telugu | te | | | | Gujarati | gu | | | | Thai | th | th | th | | Haitian Creole | ht | | | | Turkish | tr | | tr | | Hebrew | iw | | | | Ukrainian | uk | | | | Hindi | hi | | hi | | Urdu | ur | | | | Hungarian | hu | | | | Vietnamese | vi | vi | vi | | Icelandic | is | | | | Welsh | cy | | | | Indonesian | id | id | id | | Yiddish | yi | | |