Skip to content

Commit 40c90a9

Browse files
authored
Merge pull request #285 from ma10/eliminate-hardcoded-values-20250221
yaml2xのリファクタリング
2 parents eeb8b9d + e556de1 commit 40c90a9

28 files changed

+556
-656
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ build/
77
incfiles.mk
88
__pycache__/
99
*:Zone.Identifier
10+
*.egg-info/

requirements.txt

-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,3 @@ google-api-python-client
1212
pytz
1313
pydantic
1414
tools/yaml2x/libs/freee_a11y_gl
15-
tools/yaml2x/libs/get_yaml_data

tools/yaml2x/libs/freee_a11y_gl/freee_a11y_gl/__init__.py

+15
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,18 @@
44
from .initializer import setup_instances
55
from .info_utils import get_info_links
66
from .version_utils import get_version_info
7+
from .yaml_processor import process_yaml_data
8+
9+
__all__ = [
10+
# Existing exports from classes
11+
'Category', 'Check', 'Guideline', 'Faq', 'FaqTag',
12+
'WcagSc', 'InfoRef', 'AxeRule', 'CheckTool',
13+
# Constants
14+
'PLATFORM_NAMES', 'SEVERITY_TAGS', 'CHECK_TARGETS',
15+
'IMPLEMENTATION_TARGETS',
16+
# Utils
17+
'get_src_path', 'setup_instances', 'get_info_links',
18+
'get_version_info',
19+
# YAML processing functionality
20+
'process_yaml_data'
21+
]

tools/yaml2x/libs/freee_a11y_gl/freee_a11y_gl/classes.py

+8-27
Original file line numberDiff line numberDiff line change
@@ -695,42 +695,23 @@ def procedures(self):
695695
return procedures
696696

697697
def summary(self, lang):
698-
language_info = {
699-
'ja': {
700-
'simple_pass_singular': 'を満たしている',
701-
'simple_pass_plural': 'を満たしている',
702-
'and_connector': '、かつ',
703-
'or_connector': '、または',
704-
'and_separator': 'と',
705-
'or_separator': 'または'
706-
},
707-
'en': {
708-
'simple_pass_singular': ' is true',
709-
'simple_pass_plural': ' are true',
710-
'and_connector': ', and ',
711-
'or_connector': ', or ',
712-
'and_separator': ' and ',
713-
'or_separator': ' or '
714-
},
715-
}
716-
717698
if self.type == 'simple':
718-
return f'{self.procedure.id}{language_info[lang]["simple_pass_singular"]}'
699+
return f'{self.procedure.id}{Config.get_pass_singular_text(lang)}'
719700

720701
simple_conditions = [cond.summary(lang) for cond in self.conditions if cond.type == 'simple']
721702
complex_conditions = [f'({cond.summary(lang)})' for cond in self.conditions if cond.type != 'simple']
722703

723704
if self.type == 'and':
724-
summary_separator = language_info[lang]['and_separator']
725-
summary_connector = language_info[lang]['and_connector']
726-
simple_pass = language_info[lang]['simple_pass_plural']
705+
summary_separator = Config.get_separator(lang, "and")
706+
summary_connector = Config.get_conjunction(lang, "and")
707+
simple_pass = Config.get_pass_plural_text(lang)
727708
else:
728-
summary_separator = language_info[lang]['or_separator']
729-
summary_connector = language_info[lang]['or_connector']
730-
simple_pass = language_info[lang]['simple_pass_singular']
709+
summary_separator = Config.get_separator(lang, "or")
710+
summary_connector = Config.get_conjunction(lang, "or")
711+
simple_pass = Config.get_pass_singular_text(lang)
731712

732713
if len(simple_conditions) > 1:
733-
simple_conditions = [cond.replace(language_info[lang]['simple_pass_singular'], '') for cond in simple_conditions]
714+
simple_conditions = [cond.replace(Config.get_pass_singular_text(lang), '') for cond in simple_conditions]
734715
simple_summary = f'{summary_separator.join(simple_conditions)}{simple_pass}'
735716
return f'{simple_summary}{summary_connector}{summary_connector.join(complex_conditions)}' if complex_conditions else simple_summary
736717
else:

tools/yaml2x/libs/freee_a11y_gl/freee_a11y_gl/config.development.yaml

-42
This file was deleted.

tools/yaml2x/libs/freee_a11y_gl/freee_a11y_gl/config.production.yaml

-47
This file was deleted.

tools/yaml2x/libs/freee_a11y_gl/freee_a11y_gl/config.py

+55-13
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ def register_settings(cls, new_settings: Optional[Dict[str, any]] = None) -> Non
1313
"""Register new settings."""
1414
settings.update(new_settings)
1515

16+
@classmethod
17+
def set_base_url(cls, base_url: str) -> None:
18+
"""Set the base URL for the site.
19+
20+
Args:
21+
base_url: Base URL (e.g., https://a11y-guidelines.freee.co.jp)
22+
"""
23+
settings.update({"base_url": base_url.rstrip("/")})
24+
1625
@classmethod
1726
def get_basedir(cls) -> str:
1827
"""Get base directory path.
@@ -22,54 +31,89 @@ def get_basedir(cls) -> str:
2231
"""
2332
return settings.get("basedir", ".")
2433

34+
@classmethod
35+
def _get_language_path(cls, lang: LanguageCode) -> str:
36+
"""Get the language-specific path segment.
37+
38+
Args:
39+
lang: Language code
40+
41+
Returns:
42+
Language path segment ("" for ja, "/en" for en)
43+
"""
44+
return "" if lang == "ja" else f"/{lang}"
45+
2546
@classmethod
2647
def get_base_url(cls, lang: Optional[LanguageCode] = None) -> str:
27-
"""Get base URL for specified language."""
48+
"""Get base URL with language path for specified language.
49+
50+
Args:
51+
lang: Language code. If None, default language from settings will be used.
52+
53+
Returns:
54+
Base URL with language path
55+
"""
2856
effective_lang = lang if lang is not None else settings.get("languages.default", "ja")
29-
return settings.get(f"base_url.{effective_lang}", "")
57+
base = settings.get("base_url", "")
58+
lang_path = cls._get_language_path(effective_lang)
59+
return f"{base}{lang_path}"
3060

3161
@classmethod
3262
def get_guidelines_path(cls) -> str:
3363
"""Get guidelines (categories) path."""
34-
return settings.get("paths.guidelines", "/")
64+
return settings.get("paths.guidelines", "/categories/")
3565

3666
@classmethod
3767
def get_separator(cls, lang: Optional[LanguageCode] = None, separator_type: Optional[str] = None) -> str:
3868
"""Get separator of specified type for language."""
3969
effective_lang = lang if lang is not None else settings.get("languages.default", "ja")
4070
effective_type = separator_type if separator_type is not None else "text"
41-
return settings.get(f"separators.{effective_type}.{effective_lang}", "")
71+
return settings.get(f"locale.{effective_lang}.{effective_type}_separator", "")
4272

4373
@classmethod
4474
def get_text_separator(cls, lang: Optional[LanguageCode] = None) -> str:
4575
"""Get text separator for specified language."""
4676
effective_lang = lang if lang is not None else settings.get("languages.default", "ja")
47-
return settings.get(f"separators.text.{effective_lang}", "")
77+
return settings.get(f"locale.{effective_lang}.text_separator", "")
4878

4979
@classmethod
5080
def get_list_separator(cls, lang: Optional[LanguageCode] = None) -> str:
5181
"""Get list item separator for specified language."""
5282
effective_lang = lang if lang is not None else settings.get("languages.default", "ja")
53-
return settings.get(f"separators.list.{effective_lang}", ", ")
83+
return settings.get(f"locale.{effective_lang}.list_separator", ", ")
5484

5585
@classmethod
56-
def get_pass_text(cls, lang: Optional[LanguageCode] = None) -> str:
86+
def get_pass_singular_text(cls, lang: Optional[LanguageCode] = None) -> str:
5787
"""Get localized pass text for conditions.
5888
5989
Args:
6090
lang: Language code. If None, default language from settings will be used.
6191
6292
Returns:
63-
Localized pass text
93+
Localized pass text for single condition
6494
"""
6595
effective_lang = lang if lang is not None else settings.get("languages.default", "ja")
66-
return settings.get(f"separators.pass_text.{effective_lang}", " is true")
96+
return settings.get(f"locale.{effective_lang}.pass_singular_text", " is true")
6797

98+
@classmethod
99+
def get_pass_plural_text(cls, lang: Optional[LanguageCode] = None) -> str:
100+
"""Get localized pass text for conditions.
101+
102+
Args:
103+
lang: Language code. If None, default language from settings will be used.
104+
105+
Returns:
106+
Localized pass text for multiple conditions
107+
"""
108+
effective_lang = lang if lang is not None else settings.get("languages.default", "ja")
109+
return settings.get(f"locale.{effective_lang}.pass_plural_text", " are true")
110+
111+
@classmethod
68112
def get_conjunction(cls, lang: Optional[LanguageCode] = None, conjunction_type: Optional[str] = None) -> str:
69113
"""Get conjunction of specified type for language."""
70114
effective_lang = lang if lang is not None else settings.get("languages.default", "ja")
71115
effective_type = conjunction_type if conjunction_type is not None else "and"
72-
return settings.get(f"separators.{effective_type}_conjunction.{effective_lang}", " and ")
116+
return settings.get(f"locale.{effective_lang}.{effective_type}_conjunction", "and")
73117

74118
@classmethod
75119
def get_check_tool_name(cls, tool_id: str, lang: Optional[LanguageCode] = None) -> str:
@@ -135,7 +179,6 @@ def get_faq_path(cls) -> str:
135179

136180
@classmethod
137181
def get_examples_url(cls, lang: Optional[LanguageCode] = None) -> str:
138-
"""Get examples base URL for specified language."""
139182
"""Get examples base URL for specified language.
140183
141184
Args:
@@ -147,7 +190,6 @@ def get_examples_url(cls, lang: Optional[LanguageCode] = None) -> str:
147190
base_url = cls.get_base_url(lang)
148191
return f"{base_url}/checks/examples/"
149192

150-
@staticmethod
151193
@classmethod
152194
def get_date_format(cls, lang: Optional[LanguageCode] = None) -> str:
153195
"""Get localized date format string.
@@ -160,7 +202,7 @@ def get_date_format(cls, lang: Optional[LanguageCode] = None) -> str:
160202
"""
161203
effective_lang = lang if lang is not None else settings.get("languages.default", "ja")
162204
default_format = "%Y年%-m月%-d日" if effective_lang == "ja" else "%B %-d, %Y"
163-
return settings.get(f"formats.date.{effective_lang}", default_format)
205+
return settings.get(f"locale.{effective_lang}.date_format", default_format)
164206

165207
@staticmethod
166208
def tag2sc(tag: str) -> str:

0 commit comments

Comments
 (0)