Skip to content
This repository has been archived by the owner on Mar 11, 2024. It is now read-only.

Commit

Permalink
Update languages
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhail-vl committed Oct 25, 2023
1 parent 5741200 commit c06f233
Show file tree
Hide file tree
Showing 12 changed files with 122 additions and 22 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## 3.2.0 (IN PROGRESS)

### Features / Enhancements

- Add internationalization i18n (#29)

## 3.1.0 (2023-10-14)

### Features / Enhancements
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

![App](https://github.com/VolkovLabs/volkovlabs-abc-app/raw/main/src/img/app.png)

![Grafana 10](https://img.shields.io/badge/Grafana-10.1-orange)
![Grafana](https://img.shields.io/badge/Grafana-10.1-orange)
![CI](https://github.com/volkovlabs/volkovlabs-abc-app/workflows/CI/badge.svg)
![E2E](https://github.com/volkovlabs/volkovlabs-abc-app/workflows/E2E/badge.svg)
[![codecov](https://codecov.io/gh/VolkovLabs/volkovlabs-abc-app/branch/main/graph/badge.svg?token=2W9VR0PG5N)](https://codecov.io/gh/VolkovLabs/volkovlabs-abc-app)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,5 @@
"test:ci": "jest --maxWorkers 4 --coverage",
"upgrade": "npm upgrade --save"
},
"version": "3.1.0"
"version": "3.2.0"
}
13 changes: 12 additions & 1 deletion src/constants/app.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
import { SupportedLanguage } from '../types';

/**
* Languages
*/
export const enum Languages {
DE = 'de',
EN = 'en',
ES = 'es',
FR = 'fr',
ZH = 'zh',
}

/**
* Default Language
*/
export const DefaultLanguage: SupportedLanguage = 'en';
export const DefaultLanguage: SupportedLanguage = Languages.EN;

/**
* App Information
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/__mocks__/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import i18next from 'i18next';
import { initReactI18next } from 'react-i18next';
import { resources } from '../translations';
import { Languages } from '../../constants';

/**
* Default Namespace
Expand All @@ -11,7 +12,7 @@ export const defaultNS = 'translation';
* Init i18next
*/
i18next.use(initReactI18next).init({
lng: 'en',
lng: Languages.EN,
debug: false,
resources,
defaultNS,
Expand Down
12 changes: 12 additions & 0 deletions src/i18n/translations/de.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"configPages": {
"config": "Config"
},
"home": {
"greeting": "Hello World!"
},
"config": {
"description": "The Abc App, is a plugin for Grafana that...",
"updateButton": "Update Settings"
}
}
12 changes: 12 additions & 0 deletions src/i18n/translations/es.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"configPages": {
"config": "Config"
},
"home": {
"greeting": "Hello World!"
},
"config": {
"description": "The Abc App, is a plugin for Grafana that...",
"updateButton": "Update Settings"
}
}
12 changes: 12 additions & 0 deletions src/i18n/translations/fr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"configPages": {
"config": "Config"
},
"home": {
"greeting": "Hello World!"
},
"config": {
"description": "The Abc App, is a plugin for Grafana that...",
"updateButton": "Update Settings"
}
}
32 changes: 32 additions & 0 deletions src/i18n/translations/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import de from './de.json';
import en from './en.json';
import es from './es.json';
import fr from './fr.json';
import zh from './zh.json';

/**
* Translation Resources
Expand All @@ -10,4 +14,32 @@ export const resources = {
en: {
translation: en,
},

/**
* Spanish
*/
es: {
translation: es,
},

/**
* French
*/
fr: {
translation: fr,
},

/**
* German
*/
de: {
translation: de,
},

/**
* Chinese
*/
zh: {
translation: zh,
},
} as const;
12 changes: 12 additions & 0 deletions src/i18n/translations/zh.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"configPages": {
"config": "Config"
},
"home": {
"greeting": "Hello World!"
},
"config": {
"description": "The Abc App, is a plugin for Grafana that...",
"updateButton": "Update Settings"
}
}
4 changes: 3 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Languages } from './constants';

/**
* App Settings
*/
Expand All @@ -6,4 +8,4 @@ export interface AppSettings {}
/**
* Supported Language
*/
export type SupportedLanguage = 'en' | 'es' | 'fr' | 'de' | 'zh';
export type SupportedLanguage = Languages.EN | Languages.ES | Languages.FR | Languages.DE | Languages.ZH;
34 changes: 17 additions & 17 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import { config } from '@grafana/runtime';
import { DefaultLanguage } from './constants';
import { DefaultLanguage, Languages } from './constants';
import { SupportedLanguage } from './types';

/**
* Get User Language
* @param fallback
*/
export const getUserLanguage = (fallback = DefaultLanguage): SupportedLanguage => {
const locale = config?.bootData?.user?.language;
const lang = locale?.split('-')?.[0];
const locale = config?.bootData?.user?.language;
const lang = locale?.split('-')?.[0];

/**
* Validate supported languages
*/
switch (lang) {
case 'en':
case 'es':
case 'fr':
case 'de':
case 'zh': {
return lang;
}
/**
* Validate supported languages
*/
switch (lang) {
case Languages.EN:
case Languages.ES:
case Languages.FR:
case Languages.DE:
case Languages.ZH: {
return lang;
}

default: {
return fallback;
}
default: {
return fallback;
}
}
};

0 comments on commit c06f233

Please sign in to comment.