this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Use translated rules for report post modal

+80 -37
+52 -9
src/components/report-modal.jsx
··· 6 6 import { useMemo, useRef, useState } from 'preact/hooks'; 7 7 8 8 import { api } from '../utils/api'; 9 + import localeMatch from '../utils/locale-match'; 9 10 import showToast from '../utils/show-toast'; 10 11 import { getCurrentInstance } from '../utils/store-utils'; 11 12 ··· 17 18 // NOTE: `dislike` hidden for now, it's actually not used for reporting 18 19 // Mastodon shows another screen for unfollowing, muting or blocking instead of reporting 19 20 20 - const CATEGORIES = [/*'dislike'*/ , 'spam', 'legal', 'violation', 'other']; 21 + const CATEGORIES = [/*'dislike' ,*/ 'spam', 'legal', 'violation', 'other']; 21 22 // `violation` will be set if there are `rule_ids[]` 22 23 23 24 const CATEGORIES_INFO = { ··· 45 46 }, 46 47 }; 47 48 49 + function findMatchingLanguage(rule, currentLang) { 50 + if (!rule.translations || !currentLang) return null; 51 + const availableLanguages = Object.keys(rule.translations); 52 + if (!availableLanguages?.length) return null; 53 + 54 + let matchedLang = localeMatch([currentLang], availableLanguages, null); 55 + if (!matchedLang) { 56 + // localeMatch fails if there are keys like zhCn, zhTw 57 + // Convert them something like zh-CN first, try again 58 + // Detect uppercase, then split by dash 59 + const normalizedLanguages = availableLanguages.map((lang) => { 60 + const parts = lang.split(/(?=[A-Z])/); 61 + return parts 62 + .map((part, i) => (i === 0 ? part : part.toLowerCase())) 63 + .join('-'); 64 + }); 65 + matchedLang = localeMatch([currentLang], normalizedLanguages, null); 66 + } 67 + 68 + // If matchedLang has dash, convert back to original format 69 + // E.g. zh-cn to zhCn 70 + if (matchedLang && matchedLang.includes('-')) { 71 + const [lang, region] = matchedLang.split('-'); 72 + matchedLang = lang + region.charAt(0).toUpperCase() + region.slice(1); 73 + } 74 + 75 + return matchedLang; 76 + } 77 + 78 + function translateRules(rules, currentLang) { 79 + if (!rules?.length) return []; 80 + if (!currentLang) return rules; 81 + return rules.map((rule) => { 82 + const matchedLang = findMatchingLanguage(rule, currentLang); 83 + return { 84 + ...rule, 85 + _translatedText: rule.translations?.[matchedLang]?.text || null, 86 + }; 87 + }); 88 + } 89 + 48 90 function ReportModal({ account, post, onClose }) { 49 - const { _, t } = useLingui(); 91 + const { _, t, i18n } = useLingui(); 50 92 const { masto } = api(); 51 93 const [uiState, setUIState] = useState('default'); 52 94 const [username, domain] = account.acct.split('@'); 53 95 54 - const [rules, currentDomain] = useMemo(() => { 96 + const [translatedRules, currentDomain] = useMemo(() => { 55 97 const { rules, domain } = getCurrentInstance(); 56 - return [rules || [], domain]; 57 - }); 98 + const rawRules = rules || []; 99 + return [translateRules(rawRules, i18n.locale), domain]; 100 + }, [i18n.locale]); 58 101 59 102 const [selectedCategory, setSelectedCategory] = useState(null); 60 103 const [showRules, setShowRules] = useState(false); ··· 165 208 </p> 166 209 <section class="report-categories"> 167 210 {CATEGORIES.map((category) => 168 - category === 'violation' && !rules?.length ? null : ( 211 + category === 'violation' && !translatedRules?.length ? null : ( 169 212 <Fragment key={category}> 170 213 <label class="report-category"> 171 214 <input ··· 186 229 </small> 187 230 </span> 188 231 </label> 189 - {category === 'violation' && !!rules?.length && ( 232 + {category === 'violation' && !!translatedRules?.length && ( 190 233 <div 191 234 class="shazam-container no-animation" 192 235 hidden={!showRules} 193 236 > 194 237 <div class="shazam-container-inner"> 195 238 <div class="report-rules" ref={rulesRef}> 196 - {rules.map((rule, i) => ( 239 + {translatedRules.map((rule, i) => ( 197 240 <label class="report-rule" key={rule.id}> 198 241 <input 199 242 type="checkbox" ··· 216 259 } 217 260 }} 218 261 /> 219 - <span>{rule.text}</span> 262 + <span>{rule._translatedText || rule.text}</span> 220 263 </label> 221 264 ))} 222 265 </div>
+28 -28
src/locales/en.po
··· 462 462 #: src/components/media-alt-modal.jsx:43 463 463 #: src/components/media-modal.jsx:327 464 464 #: src/components/notification-service.jsx:157 465 - #: src/components/report-modal.jsx:75 465 + #: src/components/report-modal.jsx:118 466 466 #: src/components/shortcuts-settings.jsx:230 467 467 #: src/components/shortcuts-settings.jsx:583 468 468 #: src/components/shortcuts-settings.jsx:783 ··· 1770 1770 msgid "{0}h" 1771 1771 msgstr "" 1772 1772 1773 - #: src/components/report-modal.jsx:29 1773 + #: src/components/report-modal.jsx:30 1774 1774 msgid "Spam" 1775 1775 msgstr "" 1776 1776 1777 - #: src/components/report-modal.jsx:30 1777 + #: src/components/report-modal.jsx:31 1778 1778 msgid "Malicious links, fake engagement, or repetitive replies" 1779 1779 msgstr "" 1780 1780 1781 - #: src/components/report-modal.jsx:33 1781 + #: src/components/report-modal.jsx:34 1782 1782 msgid "Illegal" 1783 1783 msgstr "" 1784 1784 1785 - #: src/components/report-modal.jsx:34 1785 + #: src/components/report-modal.jsx:35 1786 1786 msgid "Violates the law of your or the server's country" 1787 1787 msgstr "" 1788 1788 1789 - #: src/components/report-modal.jsx:37 1789 + #: src/components/report-modal.jsx:38 1790 1790 msgid "Server rule violation" 1791 1791 msgstr "" 1792 1792 1793 - #: src/components/report-modal.jsx:38 1793 + #: src/components/report-modal.jsx:39 1794 1794 msgid "Breaks specific server rules" 1795 1795 msgstr "" 1796 1796 1797 - #: src/components/report-modal.jsx:39 1797 + #: src/components/report-modal.jsx:40 1798 1798 msgid "Violation" 1799 1799 msgstr "" 1800 1800 1801 - #: src/components/report-modal.jsx:42 1801 + #: src/components/report-modal.jsx:43 1802 1802 msgid "Other" 1803 1803 msgstr "" 1804 1804 1805 - #: src/components/report-modal.jsx:43 1805 + #: src/components/report-modal.jsx:44 1806 1806 msgid "Issue doesn't fit other categories" 1807 1807 msgstr "" 1808 1808 1809 - #: src/components/report-modal.jsx:68 1809 + #: src/components/report-modal.jsx:111 1810 1810 msgid "Report Post" 1811 1811 msgstr "" 1812 1812 1813 - #: src/components/report-modal.jsx:68 1813 + #: src/components/report-modal.jsx:111 1814 1814 msgid "Report @{username}" 1815 1815 msgstr "" 1816 1816 1817 - #: src/components/report-modal.jsx:104 1817 + #: src/components/report-modal.jsx:147 1818 1818 msgid "Pending review" 1819 1819 msgstr "" 1820 1820 1821 - #: src/components/report-modal.jsx:146 1821 + #: src/components/report-modal.jsx:189 1822 1822 msgid "Post reported" 1823 1823 msgstr "" 1824 1824 1825 - #: src/components/report-modal.jsx:146 1825 + #: src/components/report-modal.jsx:189 1826 1826 msgid "Profile reported" 1827 1827 msgstr "" 1828 1828 1829 - #: src/components/report-modal.jsx:154 1829 + #: src/components/report-modal.jsx:197 1830 1830 msgid "Unable to report post" 1831 1831 msgstr "" 1832 1832 1833 - #: src/components/report-modal.jsx:155 1833 + #: src/components/report-modal.jsx:198 1834 1834 msgid "Unable to report profile" 1835 1835 msgstr "" 1836 1836 1837 - #: src/components/report-modal.jsx:163 1837 + #: src/components/report-modal.jsx:206 1838 1838 msgid "What's the issue with this post?" 1839 1839 msgstr "" 1840 1840 1841 - #: src/components/report-modal.jsx:164 1841 + #: src/components/report-modal.jsx:207 1842 1842 msgid "What's the issue with this profile?" 1843 1843 msgstr "" 1844 1844 1845 - #: src/components/report-modal.jsx:233 1845 + #: src/components/report-modal.jsx:276 1846 1846 msgid "Additional info" 1847 1847 msgstr "" 1848 1848 1849 - #: src/components/report-modal.jsx:256 1849 + #: src/components/report-modal.jsx:299 1850 1850 msgid "Forward to <0>{domain}</0>" 1851 1851 msgstr "" 1852 1852 1853 - #: src/components/report-modal.jsx:266 1853 + #: src/components/report-modal.jsx:309 1854 1854 msgid "Send Report" 1855 1855 msgstr "" 1856 1856 1857 - #: src/components/report-modal.jsx:275 1857 + #: src/components/report-modal.jsx:318 1858 1858 msgid "Muted {username}" 1859 1859 msgstr "" 1860 1860 1861 - #: src/components/report-modal.jsx:278 1861 + #: src/components/report-modal.jsx:321 1862 1862 msgid "Unable to mute {username}" 1863 1863 msgstr "" 1864 1864 1865 - #: src/components/report-modal.jsx:283 1865 + #: src/components/report-modal.jsx:326 1866 1866 msgid "Send Report <0>+ Mute profile</0>" 1867 1867 msgstr "" 1868 1868 1869 - #: src/components/report-modal.jsx:294 1869 + #: src/components/report-modal.jsx:337 1870 1870 msgid "Blocked {username}" 1871 1871 msgstr "" 1872 1872 1873 - #: src/components/report-modal.jsx:297 1873 + #: src/components/report-modal.jsx:340 1874 1874 msgid "Unable to block {username}" 1875 1875 msgstr "" 1876 1876 1877 - #: src/components/report-modal.jsx:302 1877 + #: src/components/report-modal.jsx:345 1878 1878 msgid "Send Report <0>+ Block profile</0>" 1879 1879 msgstr "" 1880 1880