Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/mrgnw/ananas. learn multiple languages at once ananas.xcc.es
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125import { languages } from 'countries-list'
// Import JSON data directly - Vite handles JSON imports nativelyimport languageData from '$lib/data/wikidata-languages.json'import countriesData from '$lib/data/wikidata-countries.json'
// Todo: language statistic by region// language statisticts https://www.simonandsimon.co.uk/blog/global-language-statistics-by-country// TODO: language recommendation by language selection
// Get all languages from countries-listexport function getCountryLanguages() { return Object.keys(languages).sort()}
// Default languages from NewLang.svelte - using 3-character ISO codesexport const defaultLanguages = { eng: { label: 'English', native: 'English', rtl: false, display: true }, rus: { label: 'Russian', native: 'Русский', rtl: false, display: true }, jpn: { label: 'Japanese', native: '日本語', rtl: false, display: true }, spa: { label: 'Spanish', native: 'Español', rtl: false, display: true }, ita: { label: 'Italian', native: 'Italiano', rtl: false, display: true }, cat: { label: 'Catalan', native: 'Català', rtl: false, display: true }}
// Get all available languages from Wikidataexport function getAllLanguages() { return languageData.map(lang => ({ code: lang.iso, name: lang.langLabel, nativeName: lang.nativeNames?.[0] || lang.langLabel, speakers: lang.speakers }))}
// Convert language code to name using countries-list dataexport function getLanguageName(code) { if (!code) return ''; const wikiLang = languageData.find(l => l.iso === code) if (wikiLang) { return wikiLang.nativeNames?.[0] || wikiLang.langLabel } if (defaultLanguages[code]) { return defaultLanguages[code].native } if (languages[code]) { return languages[code].native || languages[code].name } return code.toUpperCase()}
// Get English name of language if availableexport function getEnglishName(code) { if (!code) return ''; const wikiLang = languageData.find(l => l.iso === code) if (wikiLang) { return wikiLang.langLabel } if (defaultLanguages[code]) { return defaultLanguages[code].label } if (languages[code]) { return languages[code].name } return code.toUpperCase()}
// Get language info from wikidataexport function getLanguageInfo(code) { if (!code) return null const wikiLang = languageData.find(l => l.iso === code) return wikiLang ? { ...wikiLang, rtl: wikiLang.rtl || false } : null}
// Get country information by ISO codeexport function getCountryInfo(countryCode) { if (!countryCode) return null return countriesData.find(country => country.iso === countryCode.toLowerCase())}
// Search languages with smart rankingexport function searchLanguages(query, country = null) { if (!query && !country) return getAllLanguages() const searchStr = query.toLowerCase() return getAllLanguages().filter(lang => { const matchesSearch = !query || lang.code.toLowerCase().includes(searchStr) || lang.name.toLowerCase().includes(searchStr) || lang.nativeName.toLowerCase().includes(searchStr) const matchesCountry = !country || languageData.find(l => l.iso === lang.code)?.countries?.includes(country) return matchesSearch && matchesCountry })}
// Sort languages by country and native speakersfunction sortLanguages(codes, userCountry = null) { return codes.sort((a, b) => { const langA = languageData.find(l => l.iso === a) const langB = languageData.find(l => l.iso === b) // If we have country data, prioritize languages from user's country if (userCountry) { const aInCountry = langA?.countries?.includes(userCountry) || false const bInCountry = langB?.countries?.includes(userCountry) || false if (aInCountry !== bInCountry) { return aInCountry ? -1 : 1 } } // Then sort by number of native speakers const speakersA = langA?.nativeSpeakers_k || 0 const speakersB = langB?.nativeSpeakers_k || 0 return speakersB - speakersA })}