0.0.7 • Published 1 year ago

@simple-translation-helper/vue v0.0.7

Weekly downloads
-
License
-
Repository
-
Last release
1 year ago

Simple translation helper for Vue 3

This package provides a simple translation helper for Vue 3.

Installation

npm i @simple-translation-helper/vue

Add styling to your main.js:

import "@simple-translation-helper/vue/style.css"

If you want the ability to display the translation keys add the translation-hub component to your App.vue:

<translation-hub :active="conditionToShowHub"/>

Translation hub

The translation-hub is a button that you can use to display the translation keys. This is useful for debugging and for providing a way for translators to see the keys that need to be translated.

Props

PropTypeDefaultDescription
activeBooleanfalseDetermines whether the component is active or not.
activeBackgroundColorString#0891b2Determines the active color of the transltion hub button.
positionString"top-right"Determines the position of the component on the page. It must be one of "top-left", "top-right", "bottom-left", or "bottom-right".

Slots

The component has one default slot that can be used to provide custom content to be displayed instead of the translation keys toggle button. The slot can receive the following property:

PropertyTypeDescription
showTranslationKeysFunctionA function that shows the translation keys.
hideTranslationKeysFunctionA function that hides the translation keys

Example Usage with slots

<template>
  <div>
    <translation-hub>
      <template #default="{ showTranslationKeys, hideTranslationKeys }">
        <button @click="showTranslationKeys">
          Show keys
        </button>
        <button @click="hideTranslationKeys">
          Show keys
        </button>
      </template>
    </translation-hub>
  </div>
</template>

Translate Component

The translate component designed to display translations of text and give you the option to display the translation key.

Props

NameTypeRequiredDescription
translationKeyStringYesThe translation key
translationStringYesThe translated text

Slots

The translate component has one default slot, which can be used to provide custom content for the component.

Usage example

Here is an example of how you can use the translate component:

<template>
  <translate translation-key="greeting" translation="Hello, world!" />
</template>

In this example, the component will look up the translation for the greeting key with your translation method. If a translation is found, it will be displayed. Otherwise, the default text "Hello, world!" will be displayed.

You can also use the default slot to provide custom content:

<template>
  <translate translation-key="dashboard.title" translation="Welcome to my dashboard">
    Fallback text
  </translate>
</template>
0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago