feat(Text to NATO): add other languages, upper/lower and other
Add support for many languages and countries ((International), (France), (Belgium), (Switzerland), (Québec), (Germany, 2022), (Austria), (Germany, informal, 2022), (Netherlands), Italian, Spanish, (Brazil), (Portugal), Swedish, Danish, Norwegian, Finnish, Turkish, Romanian, Czech, Yugoslav, Serbian, Slovene, Russian, Korean, Greek, Japanese) Handle uppercase/lowercase and some punctuations Fix #794
This commit is contained in:
parent
d3b32cc14e
commit
1b1be10762
1580
src/tools/text-to-nato-alphabet/nato.alphabets.json
Normal file
1580
src/tools/text-to-nato-alphabet/nato.alphabets.json
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,28 +1,29 @@
|
|||||||
export const natoAlphabet = [
|
export const allLanguagesAndCountries = [
|
||||||
'Alpha',
|
'(International)',
|
||||||
'Bravo',
|
'(France)',
|
||||||
'Charlie',
|
'(Belgium)',
|
||||||
'Delta',
|
'(Switzerland)',
|
||||||
'Echo',
|
'(Québec)',
|
||||||
'Foxtrot',
|
'(Germany, 2022)',
|
||||||
'Golf',
|
'(Austria)',
|
||||||
'Hotel',
|
'(Germany, informal, 2022)',
|
||||||
'India',
|
'(Netherlands)',
|
||||||
'Juliet',
|
'Italian',
|
||||||
'Kilo',
|
'Spanish',
|
||||||
'Lima',
|
'(Brazil)',
|
||||||
'Mike',
|
'(Portugal)',
|
||||||
'November',
|
'Swedish',
|
||||||
'Oscar',
|
'Danish',
|
||||||
'Papa',
|
'Norwegian',
|
||||||
'Quebec',
|
'Finnish',
|
||||||
'Romeo',
|
'Turkish',
|
||||||
'Sierra',
|
'Romanian',
|
||||||
'Tango',
|
'Czech',
|
||||||
'Uniform',
|
'Yugoslav',
|
||||||
'Victor',
|
'Serbian',
|
||||||
'Whiskey',
|
'Slovene',
|
||||||
'X-ray',
|
'Russian',
|
||||||
'Yankee',
|
'Korean',
|
||||||
'Zulu',
|
'Greek',
|
||||||
|
'Japanese',
|
||||||
];
|
];
|
||||||
|
|||||||
@ -1,19 +1,32 @@
|
|||||||
import { natoAlphabet } from './text-to-nato-alphabet.constants';
|
import allAlphabets from './nato.alphabets.json';
|
||||||
|
|
||||||
|
type AllALphabetsKeys = keyof typeof allAlphabets[0];
|
||||||
|
|
||||||
export { textToNatoAlphabet };
|
export { textToNatoAlphabet };
|
||||||
|
|
||||||
function getLetterPositionInAlphabet({ letter }: { letter: string }) {
|
function textToNatoAlphabet({ text, langOrCountry = '(International)' }: { text: string; langOrCountry: string }) {
|
||||||
return letter.toLowerCase().charCodeAt(0) - 'a'.charCodeAt(0);
|
const charRegex = new RegExp(
|
||||||
}
|
`(${
|
||||||
|
allAlphabets
|
||||||
function textToNatoAlphabet({ text }: { text: string }) {
|
.sort((a, b) => b.Letter.length - a.Letter.length)
|
||||||
|
.filter(a => a[langOrCountry as AllALphabetsKeys])
|
||||||
|
.map(a => a.Letter)
|
||||||
|
.join('|')
|
||||||
|
}|.)`,
|
||||||
|
'gi');
|
||||||
return text
|
return text
|
||||||
.split('')
|
.replace(/\s/g, ' ')
|
||||||
.map((character) => {
|
.replace(
|
||||||
const alphabetIndex = getLetterPositionInAlphabet({ letter: character });
|
charRegex,
|
||||||
const natoWord = natoAlphabet[alphabetIndex];
|
(character) => {
|
||||||
|
const searchChar = character.toUpperCase();
|
||||||
|
const isUpper = character[0].toUpperCase() === character[0];
|
||||||
|
const alphabetLetter = allAlphabets.find(letter => letter.Letter === searchChar);
|
||||||
|
if (alphabetLetter && alphabetLetter[langOrCountry as AllALphabetsKeys]) {
|
||||||
|
const natoWord = alphabetLetter[langOrCountry as AllALphabetsKeys] || '';
|
||||||
|
return ` ${isUpper ? natoWord.toUpperCase() : natoWord.toLowerCase()} `;
|
||||||
|
}
|
||||||
|
|
||||||
return natoWord ?? character;
|
return ` (${character}) `;
|
||||||
})
|
});
|
||||||
.join(' ');
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,14 +1,22 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { textToNatoAlphabet } from './text-to-nato-alphabet.service';
|
import { textToNatoAlphabet } from './text-to-nato-alphabet.service';
|
||||||
|
import { allLanguagesAndCountries } from './text-to-nato-alphabet.constants';
|
||||||
import { useCopy } from '@/composable/copy';
|
import { useCopy } from '@/composable/copy';
|
||||||
|
|
||||||
|
const lang = useStorage('text-to-nato:lang', '(International)');
|
||||||
const input = ref('');
|
const input = ref('');
|
||||||
const natoText = computed(() => textToNatoAlphabet({ text: input.value }));
|
const natoText = computed(() => textToNatoAlphabet({ text: input.value, langOrCountry: lang.value }));
|
||||||
const { copy } = useCopy({ source: natoText, text: 'NATO alphabet string copied.' });
|
const { copy } = useCopy({ source: natoText, text: 'NATO alphabet string copied.' });
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
|
<c-select
|
||||||
|
v-model:value="lang"
|
||||||
|
:options="allLanguagesAndCountries"
|
||||||
|
searchable
|
||||||
|
/>
|
||||||
|
|
||||||
<c-input-text
|
<c-input-text
|
||||||
v-model:value="input"
|
v-model:value="input"
|
||||||
label="Your text to convert to NATO phonetic alphabet"
|
label="Your text to convert to NATO phonetic alphabet"
|
||||||
@ -19,7 +27,7 @@ const { copy } = useCopy({ source: natoText, text: 'NATO alphabet string copied.
|
|||||||
|
|
||||||
<div v-if="natoText">
|
<div v-if="natoText">
|
||||||
<div mb-2>
|
<div mb-2>
|
||||||
Your text in NATO phonetic alphabet
|
Your text in NATO phonetic alphabet ({{ lang }})
|
||||||
</div>
|
</div>
|
||||||
<c-card>
|
<c-card>
|
||||||
{{ natoText }}
|
{{ natoText }}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user