Skip to content

Commit 5c9361c

Browse files
committed
bug chaotic: fix russian handling
commit_hash:88ed02330718bd73e1165ea1008ca1cce38f562a
1 parent 58b2fb6 commit 5c9361c

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

chaotic/chaotic/back/cpp/translator.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import re
77
from typing import NoReturn
88

9+
import transliterate
10+
911
from chaotic import cpp_names
1012
from chaotic import error
1113
from chaotic.back.cpp import type_name
@@ -492,7 +494,12 @@ def _gen_string(
492494

493495
@staticmethod
494496
def _normalize_name(name: str) -> str:
495-
return re.sub(NON_NAME_SYMBOL_RE, '_', name)
497+
if re.search(NON_NAME_SYMBOL_RE, name):
498+
lang = transliterate.detect_language(name, heavy_check=True)
499+
if lang:
500+
name = transliterate.translit(name, lang, reversed=True)
501+
name = re.sub(NON_NAME_SYMBOL_RE, '_', name)
502+
return name
496503

497504
def _gen_field(
498505
self,

chaotic/chaotic/cpp_names.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ def camel_case(string: str, no_lower_casing: bool = False) -> str:
1414
char = char.lower()
1515
result += char
1616
set_upper = False
17+
if not result and set_upper:
18+
result += '_'
1719
return result
1820

1921

chaotic/tests/back/cpp/test_tr_string.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def test_simple(simple_gen, cpp_primitive_type):
1616

1717

1818
def test_enum(simple_gen):
19-
types = simple_gen({'type': 'string', 'enum': ['foo', 'bar']})
19+
types = simple_gen({'type': 'string', 'enum': ['foo', 'bar', 'Русский']})
2020
assert types == {
2121
'::type': cpp_types.CppStringEnum(
2222
raw_cpp_type=type_name.TypeName('::type'),
@@ -28,6 +28,7 @@ def test_enum(simple_gen):
2828
enums=[
2929
cpp_types.CppStringEnumItem(raw_name='foo', cpp_name='kFoo'),
3030
cpp_types.CppStringEnumItem(raw_name='bar', cpp_name='kBar'),
31+
cpp_types.CppStringEnumItem(raw_name='Русский', cpp_name='kRusskij'),
3132
],
3233
),
3334
}

scripts/chaotic/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Jinja2 >= 2.10
22
PyYAML >= 6.0.1
33
pydantic >= 2.5.3
4-
4+
transliterate >= 1.10.2

0 commit comments

Comments
 (0)