Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
584 changes: 288 additions & 296 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/common/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ export const OCL_CLIENT = `oclmap/${packageJson.version}`;
export const LANGUAGES = [
{locale: 'en', name: 'English'},
{locale: 'es', name: "Español"},
{locale: 'zh', name: "中文"}
{locale: 'zh', name: "中文"},
{locale: 'pt-BR', name: "Português (Brasil)"}
]


Expand Down
32 changes: 30 additions & 2 deletions src/i18n/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,34 @@ import { initReactI18next } from 'react-i18next';
import en from './locales/en/translations.json'
import es from './locales/es/translations.json'
import zh from './locales/zh/translations.json'
import ptBR from './locales/pt-BR/translations.json'

const LANGUAGE_STORAGE_KEY = 'ocl.language'
const SUPPORTED_LANGUAGES = ['en', 'es', 'zh', 'pt-BR']

const getInitialLanguage = () => {
if(typeof window === 'undefined')
return 'en'

try {
const storedLanguage = window.localStorage.getItem(LANGUAGE_STORAGE_KEY)
return SUPPORTED_LANGUAGES.includes(storedLanguage) ? storedLanguage : 'en'
} catch(_) {
return 'en'
}
}

const persistLanguage = language => {
try {
window.localStorage.setItem(LANGUAGE_STORAGE_KEY, language)
} catch(_) {
// Keep i18n usable when browser storage is unavailable.
}
}

i18n.use(initReactI18next).init({
fallbackLng: 'en',
lng: 'en',
lng: getInitialLanguage(),
resources: {
en: {
translations: en
Expand All @@ -16,13 +40,17 @@ i18n.use(initReactI18next).init({
},
zh: {
translations: zh
},
'pt-BR': {
translations: ptBR
}
},
ns: ['translations'],
defaultNS: 'translations',
interpolation: { escapeValue: false }
});

i18n.languages = ['en', 'es', 'zh'];
i18n.languages = SUPPORTED_LANGUAGES;
i18n.on('languageChanged', persistLanguage)

export default i18n;
4 changes: 3 additions & 1 deletion src/i18n/locales/en/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,9 @@
"about_me": "About me",
"about_me_description": "Create an introduction for visiting your profile (200 characters).",
"user_has_not_created_public_repos_suffix": "has not created any public repositories",
"recent_activity": "recent activity"
"recent_activity": "recent activity",
"own_recent_activity": "Your recent activity",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these two translation keys are not used anywhere in this project

"recent_activity_of": "{{name}}'s recent activity"
},
"search": {
"filters": "Filters",
Expand Down
4 changes: 3 additions & 1 deletion src/i18n/locales/es/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,9 @@
"about_me": "Acerca de mí",
"about_me_description": "Crea una introducción para quienes visitan tu perfil (200 caracteres).",
"user_has_not_created_public_repos_suffix": "no ha creado repositorios públicos",
"recent_activity": "actividad reciente"
"recent_activity": "actividad reciente",
"own_recent_activity": "Tu actividad reciente",
"recent_activity_of": "Actividad reciente de {{name}}"
},
"search": {
"filters": "Filtros",
Expand Down
Loading
Loading