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

Icon Configuration for Languages #860

Merged
merged 1 commit into from
Nov 24, 2022
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: 8 additions & 0 deletions editor-settings.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@
"captions/source+en" = "English"
"captions/source+es" = "Spanish"

[subtitles.icons]
# A list of icons to be displayed for languages defined above.
Copy link
Member

Choose a reason for hiding this comment

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

We could mention that these are totally optional? Arguably that might be obvious, but it might also not be. And in that case, no one feels pressured into thinking up icons when they don't want.

Alternatively comment the list out?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll update the description

# Values are strings but should preferably be Unicode icons.
# These are optional and you can also choose to have no icons.
"captions/source+de" = "🇩🇪"
"captions/source+en" = "🇺🇸"
"captions/source+es" = "🇪🇸"

[subtitles.defaultVideoFlavor]
# Specify the default video in the subtitle video player by flavor
# If not specified, the editor will decide on a default by itself
Expand Down
6 changes: 6 additions & 0 deletions public/editor-settings.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ mainFlavor = "captions"
"captions/source+de" = "Deutsch"
"captions/source+en" = "English"
"captions/source+es" = "Spanish"
"captions/source" = "Generic"

[subtitles.icons]
"captions/source+de" = "🇩🇪"
"captions/source+en" = "🇺🇸"
"captions/source+es" = "🇪🇸"

[thumbnail]
show = true
5 changes: 4 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ interface iSettings {
show: boolean,
mainFlavor: string,
languages: { [key: string]: string } | undefined,
icons: { [key: string]: string } | undefined,
defaultVideoFlavor: Flavor | undefined,
}
}
Expand Down Expand Up @@ -86,7 +87,8 @@ var defaultSettings: iSettings = {
subtitles: {
show: false,
mainFlavor: "captions",
languages: undefined,
languages: {},
icons: undefined,
defaultVideoFlavor: undefined,
}
}
Expand Down Expand Up @@ -360,6 +362,7 @@ const SCHEMA = {
show: types.boolean,
mainFlavor: types.string,
languages: types.map,
icons: types.map,
defaultVideoFlavor: types.map,
},
thumbnail: {
Expand Down
30 changes: 6 additions & 24 deletions src/main/SubtitleSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ import { createTheme, ThemeProvider } from '@mui/material/styles';
setCanBeAddedFlavors(tempCanBeAddedFlavors)
}, [captionTracks, subtitles])

// TODO: Make this function more robust
const parseCountryCode = (parseString: string) => {
return parseString.split("+").pop()?.slice(0, 2);
}

const subtitleSelectStyle = css({
display: 'grid',
gridTemplateColumns: 'repeat(auto-fit, minmax(20em, 1fr))',
Expand All @@ -80,10 +75,11 @@ import { createTheme, ThemeProvider } from '@mui/material/styles';
}

for (let subFlavor of displayFlavors) {
const icon = ((settings.subtitles || {}).icons || {})[subFlavor.subFlavor];
buttons.push(
<SubtitleSelectButton
title={subFlavor.title}
iconIdentifier={parseCountryCode(subFlavor.subFlavor)}
icon={icon}
flavor={subFlavor.subFlavor}
key={subFlavor.subFlavor}
/>
Expand All @@ -106,34 +102,20 @@ import { createTheme, ThemeProvider } from '@mui/material/styles';
*/
const SubtitleSelectButton: React.FC<{
title: string,
iconIdentifier: string | undefined,
icon: string | undefined,
flavor: string,
}> = ({
title,
iconIdentifier,
icon,
flavor
}) => {
const { t } = useTranslation();
const theme = useSelector(selectTheme)
const dispatch = useDispatch()

/**
* Quick and dirty function to get a flag unicode character by country code
* @param countryCode
* @returns
*/
function getFlagEmoji(countryCode: string) {
var flag = countryCode.toUpperCase().replace(/./g, char =>
String.fromCodePoint(127397 + char.charCodeAt(0))
);
const regexEscape = /[\u{1F1E6}-\u{1F1FF}]/u;
if (regexEscape.test(flag)) {
return flag
}
}

const flagStyle = css({
fontSize: '2em',
overflow: 'hidden'
});

const titleStyle = css({
Expand All @@ -156,7 +138,7 @@ const SubtitleSelectButton: React.FC<{
dispatch(setIsDisplayEditView(true))
dispatch(setSelectedSubtitleFlavor(flavor))
}}}>
{iconIdentifier && getFlagEmoji(iconIdentifier) && <div css={flagStyle}>{getFlagEmoji(iconIdentifier)}</div>}
{icon && <div css={flagStyle}>{icon}</div>}
<div css={titleStyle}>{title}</div>
</div>
);
Expand Down