0.5.9 • Published 2 years ago

@qonsoll/translation v0.5.9

Weekly downloads
-
License
-
Repository
-
Last release
2 years ago

Firebase RealTime Database Translation

props:

  • children,
  • defaultApp
  • defaultLanguage = 'en'
  • onWrite
  • onRead
  • storage = window?.localStorage
  • languages = { name: 'English', shortCode: 'en' }
  • initialState = {}
  • useHashes = false
  • saveNewAutomatically = false
  • isLive = false

Example:

const TranslationProvider = (props) => {
  const { children, currentApp = DEFAULT_APP } = props

  // [HELPER_FUNCTIONS]
  const onWrite = useCallback(
    ({ ref, value }) => database().ref(ref).update(value),
    []
  )
  const onRead = useCallback(
    ({ ref: path, setTranslations, options }) =>
      database()
        .ref(path)
        .on(
          'value',
          (snapshot) => setTranslations(snapshot?.val() || {}),
          options
        ),
    []
  )

  return (
    <Provider
      storage={AsyncStorage}
      db={database()}
      onWrite={onWrite}
      useHashes
      onRead={onRead}
      saveNewAutomatically
      languages={LANGUAGES}
      defaultLanguage={DEFAULT_LANGUAGE}
      currentApp={currentApp}>
      <TranslationContext.Consumer>
        {({ loaded }) =>
          loaded ? children : <ScreenLoading text="Translation is loading" />
        }
      </TranslationContext.Consumer>
    </Provider>
  )
}

Context value:

  • setCurrentLanguage
  • language
  • translations
  • saveTranslationForLanguage = ({ textLabel, shortCode, refEnding, appName }) => Promise
  • loading
  • loaded
  • languages
  • translationsRDBRef: translations/${currentApp}/${language}
  • t

0.5.4

2 years ago

0.5.3

2 years ago

0.5.6

2 years ago

0.5.5

2 years ago

0.5.8

2 years ago

0.5.7

2 years ago

0.5.9

2 years ago

0.5.5-beta.1

2 years ago

0.5.2

2 years ago

0.5.1

2 years ago

0.4.8

3 years ago

0.4.7

3 years ago

0.5.0

3 years ago

0.4.5

3 years ago

0.4.6

3 years ago

0.3.9

3 years ago

0.3.6

3 years ago

0.4.4

3 years ago

0.3.5

3 years ago

0.3.8

3 years ago

0.3.7

3 years ago

0.4.1

3 years ago

0.3.2

3 years ago

0.4.0

3 years ago

0.4.3

3 years ago

0.3.4

3 years ago

0.4.2

3 years ago

0.3.3

3 years ago

0.1.10

4 years ago

0.1.11

4 years ago

0.1.12

4 years ago

0.1.13

4 years ago

0.1.14

4 years ago

0.3.0

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.9

4 years ago

0.1.4

4 years ago

0.3.1

4 years ago

0.2.2

4 years ago

0.1.3

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago