Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

797 Set the map language to UI language in new branch #6

Merged
merged 6 commits into from
May 13, 2024
Merged
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
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ on:
- v*

env:
DOCKER_USERNAME: viktorstrate
DOCKER_IMAGE: viktorstrate/photoview
DOCKER_USERNAME: kkoval
DOCKER_IMAGE: kkoval/photoview
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}

jobs:
build:
name: Build Docker Image
runs-on: ubuntu-20.04
runs-on: ubuntu-latest

steps:
- name: Checkout
Expand All @@ -40,7 +40,7 @@ jobs:
uses: docker/setup-buildx-action@v1

- name: Docker Login
if: success() && github.event_name != 'pull_request' && github.repository == 'photoview/photoview'
if: success() && github.event_name != 'pull_request' && github.repository == 'kkovaletp/photoview'
uses: docker/login-action@v2
with:
username: ${{ env.DOCKER_USERNAME }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ on:
jobs:
analyze:
name: Analyze
if: github.repository == 'photoview/photoview'
runs-on: ubuntu-20.04
if: github.repository == 'kkovaletp/photoview'
runs-on: ubuntu-latest

# strategy:
# fail-fast: false
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
jobs:
test-api:
name: Test API
runs-on: ubuntu-20.04
runs-on: ubuntu-latest

strategy:
fail-fast: false
Expand All @@ -18,7 +18,7 @@ jobs:

services:
mariadb:
image: mariadb:10.5
image: mariadb:lts
env:
MYSQL_DATABASE: photoview_test
MYSQL_USER: photoview
Expand All @@ -33,7 +33,7 @@ jobs:
- 3306:3306

postgres:
image: postgres:13.2
image: postgres:16-alpine
env:
POSTGRES_USER: photoview
POSTGRES_PASSWORD: photosecret
Expand Down
15 changes: 15 additions & 0 deletions ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@types/geojson": "^7946.0.8",
"@types/jest": "^28.1.4",
"@types/mapbox-gl": "^2.7.3",
"@mapbox/mapbox-gl-language": "^1.0.0",
"@types/react": "^18.0.15",
"@types/react-dom": "^18.0.6",
"@types/react-helmet": "^6.1.5",
Expand Down
4 changes: 1 addition & 3 deletions ui/src/Pages/PlacesPage/PlacesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ const MapPage = () => {
const { mapContainer, mapboxMap, mapboxToken } = useMapboxMap({
configureMapbox: configureMapbox({ mapboxData, dispatchMarkerMedia }),
mapboxOptions: {
projection: {
name: 'globe',
},
zoom: 1
},
})

Expand Down
3 changes: 3 additions & 0 deletions ui/src/components/mapbox/MapboxMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import styled from 'styled-components'
import 'mapbox-gl/dist/mapbox-gl.css'
import { mapboxToken } from './__generated__/mapboxToken'
import { isDarkMode } from '../../theme'
import { SetMapLanguages } from '../../localization'

const MAPBOX_TOKEN_QUERY = gql`
query mapboxToken {
Expand Down Expand Up @@ -66,6 +67,8 @@ const useMapboxMap = ({
...mapboxOptions,
})

SetMapLanguages(map.current)

configureMapbox(map.current, mapboxLibrary)
map.current?.resize()
}, [mapContainer, mapboxLibrary, mapboxData])
Expand Down
57 changes: 57 additions & 0 deletions ui/src/localization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { initReactI18next, TFunction } from 'react-i18next'
import { LanguageTranslation } from './__generated__/globalTypes'
import { authToken } from './helpers/authentication'
import { exhaustiveCheck, isNil } from './helpers/utils'
import type mapboxgl from 'mapbox-gl'
import MapboxLanguage from '@mapbox/mapbox-gl-language'

export type TranslationFn = TFunction<'translation'>

Expand Down Expand Up @@ -37,6 +39,7 @@ const SITE_TRANSLATION = gql`
}
}
`
let map_language: LanguageTranslation | null

export const loadTranslations = () => {
const [loadLang, { data }] = useLazyQuery<siteTranslation>(SITE_TRANSLATION)
Expand All @@ -54,6 +57,8 @@ export const loadTranslations = () => {
return
}

map_language = language

switch (language) {
case LanguageTranslation.Danish:
import('./extractedTranslations/da/translation.json').then(language => {
Expand Down Expand Up @@ -154,3 +159,55 @@ export const loadTranslations = () => {
exhaustiveCheck(language)
}, [data?.myUserPreferences.language])
}

export const SetMapLanguages = (map: mapboxgl.Map) => {
if (isNil(map_language)) {
map.addControl(new MapboxLanguage({ defaultLanguage: 'en' }))
return
}

switch (map_language) {
case LanguageTranslation.Danish:
map.addControl(new MapboxLanguage({ defaultLanguage: 'da' }))
return
case LanguageTranslation.English:
map.addControl(new MapboxLanguage({ defaultLanguage: 'en' }))
return
case LanguageTranslation.French:
map.addControl(new MapboxLanguage({ defaultLanguage: 'fr' }))
return
case LanguageTranslation.Swedish:
map.addControl(new MapboxLanguage({ defaultLanguage: 'sv' }))
return
case LanguageTranslation.Italian:
map.addControl(new MapboxLanguage({ defaultLanguage: 'it' }))
return
case LanguageTranslation.Spanish:
map.addControl(new MapboxLanguage({ defaultLanguage: 'es' }))
return
case LanguageTranslation.Polish:
map.addControl(new MapboxLanguage({ defaultLanguage: 'pl' }))
return
case LanguageTranslation.German:
map.addControl(new MapboxLanguage({ defaultLanguage: 'de' }))
return
case LanguageTranslation.Russian:
map.addControl(new MapboxLanguage({ defaultLanguage: 'ru' }))
return
case LanguageTranslation.TraditionalChinese:
map.addControl(new MapboxLanguage({ defaultLanguage: 'zh-Hant' }))
return
case LanguageTranslation.SimplifiedChinese:
map.addControl(new MapboxLanguage({ defaultLanguage: 'zh-Hans' }))
return
case LanguageTranslation.Portuguese:
map.addControl(new MapboxLanguage({ defaultLanguage: 'pt' }))
return
case LanguageTranslation.Basque:
map.addControl(new MapboxLanguage({ defaultLanguage: 'en' }))
return
case LanguageTranslation.Turkish:
map.addControl(new MapboxLanguage({ defaultLanguage: 'tr' }))
return
}
}
Loading