Z31457

{
    "Z1K1": "Z2",
    "Z2K1": {
        "Z1K1": "Z6",
        "Z6K1": "Z31457"
    },
    "Z2K2": {
        "Z1K1": "Z14",
        "Z14K1": "Z31456",
        "Z14K3": {
            "Z1K1": "Z16",
            "Z16K1": "Z600",
            "Z16K2": "function Z31456( text ) {\r\n\tfunction is_cyr_letter( letter ) {\r\n\t\treturn lower_case_cyr.includes( letter ) || upper_case_cyr.includes( letter );\r\n\t}\r\n\r\n\tfunction is_low_letter( letter ) {\r\n\t\treturn lower_case_cyr.includes( letter );\r\n\t}\r\n\r\n\tfunction is_apostr( letter ) {\r\n\t\treturn letter === \"'\" || letter === \"`\" || letter === \"’\";\r\n\t}\r\n\r\n\tfunction is_first_letter_of_word( text, letter_index ) {\r\n\t\treturn letter_index === 0 || !is_cyr_letter( text[letter_index - 1] );\r\n\t}\r\n\t\r\n\tfunction is_last_letter_of_word( text, letter_index ) {\r\n\t\treturn letter_index === text.length - 1 || !is_cyr_letter( text[letter_index + 1] );\r\n\t}\r\n\r\n\tfunction should_text_be_caps( text ) {\r\n\t\t// If there is only one Cyrillic letter, it should not\r\n\t\tlet count = 0;\r\n\r\n\t\tfor (let i = 0; i \u003C text.length; i++ ) {\r\n\t\t\tif ( is_cyr_letter( text[i] ) ) {\r\n\t\t\t\tcount++;\r\n\t\t\t}\r\n\t\t\tif ( count \u003E= 2 ) {\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif ( count \u003C 2 ) {\r\n\t\t\treturn false;\r\n\t\t}\r\n\r\n\t\t// If there is any lowercase letter, it should not\r\n\t\tfor (let i = 0; i \u003C text.length; i++ ) {\r\n\t\t\tif ( is_low_letter( text[i] ) ) {\r\n\t\t\t\treturn false;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// Otherwise, it should\r\n\t\treturn true;\r\n\t}\r\n\r\n\tconst upper_case_cyr = [\"А\", \"Б\", \"В\", \"Г\", \"Д\", \"Е\", \"Ё\", \"Ж\", \"З\", \"И\", \"Й\", \"К\", \"Л\", \"М\", \"Н\", \"О\", \"П\", \"Р\", \"С\", \"Т\", \"У\", \"Ф\", \"Х\", \"Ц\", \"Ч\", \"Ш\", \"Щ\", \"Ъ\", \"Ы\", \"Ь\", \"Э\", \"Ю\", \"Я\",\r\n\t\t\t\t\t\t\t\"І\", \"Ї\", \"Ѣ\", \"Ѳ\",\"Ѵ\"];\r\n\tconst lower_case_cyr = [\"а\", \"б\", \"в\", \"г\", \"д\", \"е\", \"ё\", \"ж\", \"з\", \"и\", \"й\", \"к\", \"л\", \"м\", \"н\", \"о\", \"п\", \"р\", \"с\", \"т\", \"у\", \"ф\", \"х\", \"ц\", \"ч\", \"ш\", \"щ\", \"ъ\", \"ы\", \"ь\", \"э\", \"ю\", \"я\",\r\n\t\t\t\t\t\t\t\"і\", \"ї\", \"ѣ\", \"ѳ\", \"ѵ\"];\r\n\tconst consonants = [\"б\", \"в\", \"г\", \"д\", \"ж\", \"з\", \"к\", \"л\", \"м\", \"н\", \"п\", \"р\", \"с\", \"т\", \"ф\", \"х\", \"ц\", \"ч\", \"ш\", \"щ\", \"ѳ\", \"й\"];\r\n\tconst iotated = [\"е\", \"ё\", \"ю\", \"я\", \"ѣ\"];\r\n\r\n\tconst cyr_to_lat = {\r\n\t\t\"а\": \"a\",\r\n\t\t\"б\": \"b\",\r\n\t\t\"в\": \"v\",\r\n\t\t\"г\": \"g\",\r\n\t\t\"д\": \"d\",\r\n\t\t\"е\": [\"e\", \"ye\"],\r\n\t\t\"ё\": \"yo\",\r\n\t\t\"ж\": \"zh\",\r\n\t\t\"з\": \"z\",\r\n\t\t\"и\": \"i\",\r\n\t\t\"й\": \"y\",\r\n\t\t\"к\": \"k\",\r\n\t\t\"л\": \"l\",\r\n\t\t\"м\": \"m\",\r\n\t\t\"н\": \"n\",\r\n\t\t\"о\": \"o\",\r\n\t\t\"п\": \"p\",\r\n\t\t\"р\": \"r\",\r\n\t\t\"с\": \"s\",\r\n\t\t\"т\": \"t\",\r\n\t\t\"у\": \"u\",\r\n\t\t\"ф\": \"f\",\r\n\t\t\"х\": \"kh\",\r\n\t\t\"ц\": \"ts\",\r\n\t\t\"ч\": \"ch\",\r\n\t\t\"ш\": \"sh\",\r\n\t\t\"щ\": \"shch\",\r\n\t\t\"ъ\": \"y\",\r\n\t\t\"ы\": \"y\",\r\n\t\t\"ь\": \"y\",\r\n\t\t\"э\": \"e\",\r\n\t\t\"ю\": \"yu\",\r\n\t\t\"я\": \"ya\",\r\n\t\t\"А\": \"A\",\r\n\t\t\"Б\": \"B\",\r\n\t\t\"В\": \"V\",\r\n\t\t\"Г\": \"G\",\r\n\t\t\"Д\": \"D\",\r\n\t\t\"Е\": [\"E\", \"Ye\", \"YE\"],\r\n\t\t\"Ё\": [\"Yo\", \"YO\"],\r\n\t\t\"Ж\": [\"Zh\", \"ZH\"],\r\n\t\t\"З\": \"Z\",\r\n\t\t\"И\": \"I\",\r\n\t\t\"Й\": \"Y\",\r\n\t\t\"К\": \"K\",\r\n\t\t\"Л\": \"L\",\r\n\t\t\"М\": \"M\",\r\n\t\t\"Н\": \"N\",\r\n\t\t\"О\": \"O\",\r\n\t\t\"П\": \"P\",\r\n\t\t\"Р\": \"R\",\r\n\t\t\"С\": \"S\",\r\n\t\t\"Т\": \"T\",\r\n\t\t\"У\": \"U\",\r\n\t\t\"Ф\": \"F\",\r\n\t\t\"Х\": [\"Kh\", \"KH\"],\r\n\t\t\"Ц\": [\"Ts\", \"TS\"],\r\n\t\t\"Ч\": [\"Ch\", \"CH\"],\r\n\t\t\"Ш\": [\"Sh\", \"SH\"],\r\n\t\t\"Щ\": [\"Shch\", \"SHCH\"],\r\n\t\t\"Ъ\": \"Y\",\r\n\t\t\"Ы\": \"Y\",\r\n\t\t\"Ь\": \"Y\",\r\n\t\t\"Э\": \"E\",\r\n\t\t\"Ю\": [\"Yu\", \"YU\"],\r\n\t\t\"Я\": [\"Ya\", \"YA\"],\r\n\t\t\r\n\t\t// Pre-reform letters\r\n\t\t\"і\": \"i\",\r\n\t\t\"ї\": \"i\",\r\n\t\t\"ѣ\": [\"e\", \"ye\"],\r\n\t\t\"ѳ\": \"f\",\r\n\t\t\"ѵ\": \"i\",\r\n\t\t\"І\": \"I\",\r\n\t\t\"Ї\": \"I\",\r\n\t\t\"Ѣ\": [\"E\", \"Ye\", \"YE\"],\r\n\t\t\"Ѳ\": \"F\",\r\n\t\t\"Ѵ\": \"I\"\r\n\t};\r\n\t\r\n\t\r\n\r\n\tconst result = [];\r\n\t// Is this text written in caps\r\n\tconst is_caps = should_text_be_caps( text );\r\n\r\n\t// Process letters one by one\r\n\tfor ( let i = 0; i \u003C text.length; i++ ) {\r\n\t\tconst letter = text[i];\r\n\t\tconst letterNormalized = letter.toLowerCase();\r\n\t\t\r\n\t\tif ( is_apostr( letter ) \u0026\u0026 i \u003E 0 \u0026\u0026 i \u003C ( text.length - 1 ) \u0026\u0026 is_cyr_letter( text[i - 1] ) \u0026\u0026 is_cyr_letter( text[i + 1] ) ) {\r\n\t\t\ttext = text.substring( 0, i ) + text.substring( i + 1, text.length );\r\n\t\t\ti--;\r\n\t\t} else if ( !is_cyr_letter( letter ) ) {\r\n\t\t\tresult.push( letter );\r\n\t\t} else if ( [\"е\", \"ѣ\"].includes( letterNormalized )) {\r\n\t\t\tlet case_number = 0;\r\n\t\t\tif (is_first_letter_of_word( text, i ) || !consonants.includes(text[i-1].toLowerCase())) {\r\n\t\t\t\tcase_number = is_caps ? 2 : 1;\r\n\t\t\t}\r\n\t\t\tresult.push(cyr_to_lat[letter][case_number]);\r\n\t\t\t\r\n\t\t} else if (\"й\" === letterNormalized) {\r\n\t\t\tif (i !== text.length) {\r\n\t\t\t\tresult.push(cyr_to_lat[letter])\r\n\t\t\t}\r\n\t\t} else if (\"ъ\" === letterNormalized) {\r\n\t\t\tif (is_last_letter_of_word(text, i)) {\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\tif (!iotated.includes(text[i+1].toLowerCase())) {\r\n\t\t\t\tresult.push(cyr_to_lat[letter]);\r\n\t\t\t}\r\n\t\t} else if (\"ь\" === letterNormalized) {\r\n\t\t\tif (is_last_letter_of_word(text, i) \r\n\t\t\t\t|| consonants.includes(text[i+1].toLowerCase())\r\n\t\t\t\t|| iotated.includes(text[i+1].toLowerCase())) {\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\tresult.push(cyr_to_lat[letter]);\r\n\t\t} else if (is_last_letter_of_word(text, i+1) \u0026\u0026 [\"ий\", \"ый\", \"ие\"].includes(text.substring(i,i+2).toLowerCase())) {\r\n\t\t\tconst ending = text.substring(i, i+2).toLowerCase();\r\n\t\t\tif ([\"ий\", \"ый\"].includes(ending)) {\r\n\t\t\t\tresult.push(cyr_to_lat[text[i+1]]);\r\n\t\t\t\ti++;\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\tif (\"ие\" === ending) {\r\n\t\t\t\tresult.push(cyr_to_lat[letter] + cyr_to_lat[text+1]);\r\n\t\t\t\ti++;\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\tresult.push(cyr_to_lat[letter]);\r\n\t\t} else if ( typeof( cyr_to_lat[letter] ) === \"string\" ) {\r\n\t\t\tresult.push(cyr_to_lat[letter]);\r\n\t\t} else {\r\n\t\t\tlet case_number = 0;\r\n\t\t\tif ( is_first_letter_of_word( text, i ) ) {\r\n\t\t\t\tcase_number = 0;\r\n\t\t\t}\r\n\t\t\tif ( is_caps ) {\r\n\t\t\t\tcase_number = 1;\r\n\t\t\t}\r\n\t\t\tresult.push( cyr_to_lat[letter][case_number] );\r\n\t\t}\r\n\t}\r\n\treturn result.join( \"\" );\r\n}"
        }
    },
    "Z2K3": {
        "Z1K1": "Z12",
        "Z12K1": [
            "Z11",
            {
                "Z1K1": "Z11",
                "Z11K1": "Z1002",
                "Z11K2": "Russian to English (enwiki) - JS"
            }
        ]
    },
    "Z2K4": {
        "Z1K1": "Z32",
        "Z32K1": [
            "Z31"
        ]
    },
    "Z2K5": {
        "Z1K1": "Z12",
        "Z12K1": [
            "Z11"
        ]
    }
}