python-po-lint 0.1.1__tar.gz → 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. {python_po_lint-0.1.1 → python_po_lint-0.2.0}/.github/workflows/ci.yml +4 -0
  2. {python_po_lint-0.1.1 → python_po_lint-0.2.0}/.gitignore +1 -0
  3. python_po_lint-0.2.0/LICENSE +21 -0
  4. {python_po_lint-0.1.1 → python_po_lint-0.2.0}/PKG-INFO +21 -7
  5. {python_po_lint-0.1.1 → python_po_lint-0.2.0}/README.md +20 -6
  6. {python_po_lint-0.1.1 → python_po_lint-0.2.0}/pyproject.toml +8 -2
  7. python_po_lint-0.2.0/src/po_lint/_version.py +34 -0
  8. {python_po_lint-0.1.1 → python_po_lint-0.2.0}/src/po_lint/checks.py +2 -0
  9. {python_po_lint-0.1.1 → python_po_lint-0.2.0}/src/po_lint/cli.py +11 -1
  10. {python_po_lint-0.1.1 → python_po_lint-0.2.0}/src/po_lint/config.py +2 -0
  11. {python_po_lint-0.1.1 → python_po_lint-0.2.0}/src/po_lint/linter.py +142 -37
  12. python_po_lint-0.2.0/tests/fixtures/locale/da/LC_MESSAGES/django.po +20 -0
  13. {python_po_lint-0.1.1 → python_po_lint-0.2.0}/tests/test_config.py +12 -0
  14. {python_po_lint-0.1.1 → python_po_lint-0.2.0}/tests/test_linter.py +49 -0
  15. {python_po_lint-0.1.1 → python_po_lint-0.2.0}/uv.lock +1 -1
  16. python_po_lint-0.1.1/LICENSE +0 -201
  17. {python_po_lint-0.1.1 → python_po_lint-0.2.0}/src/po_lint/__init__.py +0 -0
  18. {python_po_lint-0.1.1 → python_po_lint-0.2.0}/src/po_lint/detector.py +0 -0
  19. {python_po_lint-0.1.1 → python_po_lint-0.2.0}/tests/__init__.py +0 -0
  20. {python_po_lint-0.1.1 → python_po_lint-0.2.0}/tests/fixtures/locale/.po-lint-ignore +0 -0
  21. {python_po_lint-0.1.1 → python_po_lint-0.2.0}/tests/fixtures/locale/ar/LC_MESSAGES/django.po +0 -0
  22. {python_po_lint-0.1.1 → python_po_lint-0.2.0}/tests/fixtures/locale/fr/LC_MESSAGES/django.po +0 -0
  23. {python_po_lint-0.1.1 → python_po_lint-0.2.0}/tests/fixtures/locale/nl/LC_MESSAGES/django.po +0 -0
  24. {python_po_lint-0.1.1 → python_po_lint-0.2.0}/tests/fixtures/locale/ru/LC_MESSAGES/django.po +0 -0
  25. {python_po_lint-0.1.1 → python_po_lint-0.2.0}/tests/test_checks.py +0 -0
  26. {python_po_lint-0.1.1 → python_po_lint-0.2.0}/tests/test_cli.py +0 -0
  27. {python_po_lint-0.1.1 → python_po_lint-0.2.0}/tests/test_detector.py +0 -0
@@ -15,6 +15,8 @@ jobs:
15
15
  python-version: ["3.10", "3.11", "3.12"]
16
16
  steps:
17
17
  - uses: actions/checkout@v4
18
+ with:
19
+ fetch-depth: 0
18
20
  - uses: astral-sh/setup-uv@v4
19
21
  with:
20
22
  version: "latest"
@@ -37,6 +39,8 @@ jobs:
37
39
  id-token: write
38
40
  steps:
39
41
  - uses: actions/checkout@v4
42
+ with:
43
+ fetch-depth: 0
40
44
  - uses: astral-sh/setup-uv@v4
41
45
  with:
42
46
  version: "latest"
@@ -8,3 +8,4 @@ build/
8
8
  .pytest_cache/
9
9
  *.bin
10
10
  *.ftz
11
+ src/po_lint/_version.py
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Pescheck
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-po-lint
3
- Version: 0.1.1
3
+ Version: 0.2.0
4
4
  Summary: Lint .po translation files for contamination, wrong languages, shifts, and garbled text
5
5
  Author: PesCheck
6
6
  License-Expression: MIT
@@ -13,7 +13,7 @@ Description-Content-Type: text/markdown
13
13
 
14
14
  # python-po-lint
15
15
 
16
- Lint `.po` translation files for contamination, wrong languages, shifts, and garbled text.
16
+ Lint `.po` translation files for contamination, wrong languages, missing translations, shifts, and garbled text.
17
17
 
18
18
  Uses [fastText](https://fasttext.cc/) language identification with carrier phrase confirmation and confused language score merging for high accuracy with zero false positives.
19
19
 
@@ -22,9 +22,13 @@ Uses [fastText](https://fasttext.cc/) language identification with carrier phras
22
22
  - **Wrong language detection** — fastText-based with top-5 scoring, confused language merging, and carrier phrase confirmation
23
23
  - **Wrong script detection** — catches Cyrillic in a Dutch file, Arabic in French, Latin in Chinese, etc.
24
24
  - **Distinctive character detection** — catches Russian-specific chars in Ukrainian and vice versa
25
+ - **Fuzzy entry detection** — flags entries with the fuzzy flag that need review
26
+ - **Obsolete entry detection** — flags obsolete entries that should be removed
27
+ - **Untranslated entry detection** — flags missing translations, auto-detects source language
25
28
  - **Shifted entry detection** — finds translations that got shifted to the wrong msgid
26
29
  - **Garbled text detection** — catches corrupted/broken unicode
27
30
  - **Ignore rules** — `.po-lint-ignore` file with language scoping and msgctxt support
31
+ - **Configurable checks** — disable individual checks via `pyproject.toml` or CLI
28
32
 
29
33
  ## Installation
30
34
 
@@ -66,6 +70,9 @@ po-lint locale/ --min-detection-length 25
66
70
 
67
71
  # Specify source language (default: en)
68
72
  po-lint locale/ --source-language en
73
+
74
+ # Disable specific checks
75
+ po-lint locale/ --disable untranslated fuzzy
69
76
  ```
70
77
 
71
78
  ## Configuration
@@ -98,6 +105,10 @@ min_text_length = 3
98
105
  # Use compact fastText model instead of full
99
106
  compact_model = false
100
107
 
108
+ # Disable specific checks
109
+ # Valid: wrong_language, wrong_script, shifted_entry, garbled_text, untranslated, fuzzy, obsolete
110
+ disable = []
111
+
101
112
  # Regex patterns to ignore (matched against msgid and msgstr)
102
113
  ignore_patterns = []
103
114
  ```
@@ -122,11 +133,14 @@ screening status::Some msgid
122
133
 
123
134
  ## How it works
124
135
 
125
- 1. **Wrong script check** — fast, no model needed. Checks if the translation uses the expected writing system.
126
- 2. **Distinctive character check** — detects cross-contamination between languages sharing a script (e.g. Russian/Ukrainian).
127
- 3. **Garbled text check** — flags corrupted unicode.
128
- 4. **Shifted entry check** — flags suspiciously short translations for long source strings.
129
- 5. **Wrong language check** — uses fastText with three layers of false positive prevention:
136
+ 1. **Fuzzy entry check** — flags entries marked as fuzzy that need review.
137
+ 2. **Obsolete entry check** — flags obsolete entries that should be removed.
138
+ 3. **Untranslated entry check** — flags entries with empty `msgstr`. The source language is auto-detected (the locale where all entries are untranslated) or can be set explicitly. Skipped for the source language.
139
+ 4. **Wrong script check** — fast, no model needed. Checks if the translation uses the expected writing system.
140
+ 5. **Distinctive character check** — detects cross-contamination between languages sharing a script (e.g. Russian/Ukrainian).
141
+ 6. **Garbled text check** — flags corrupted unicode.
142
+ 7. **Shifted entry check** — flags suspiciously short translations for long source strings.
143
+ 8. **Wrong language check** — uses fastText with three layers of false positive prevention:
130
144
  - **Confused language score merging** — redistributes scores from commonly confused languages (e.g. Danish/Norwegian, Portuguese/Spanish)
131
145
  - **Source language allowance** — borrowed words from the source language are common and allowed
132
146
  - **Carrier phrase confirmation** — re-tests with a language-specific phrase prepended to distinguish false positives from real contamination
@@ -1,6 +1,6 @@
1
1
  # python-po-lint
2
2
 
3
- Lint `.po` translation files for contamination, wrong languages, shifts, and garbled text.
3
+ Lint `.po` translation files for contamination, wrong languages, missing translations, shifts, and garbled text.
4
4
 
5
5
  Uses [fastText](https://fasttext.cc/) language identification with carrier phrase confirmation and confused language score merging for high accuracy with zero false positives.
6
6
 
@@ -9,9 +9,13 @@ Uses [fastText](https://fasttext.cc/) language identification with carrier phras
9
9
  - **Wrong language detection** — fastText-based with top-5 scoring, confused language merging, and carrier phrase confirmation
10
10
  - **Wrong script detection** — catches Cyrillic in a Dutch file, Arabic in French, Latin in Chinese, etc.
11
11
  - **Distinctive character detection** — catches Russian-specific chars in Ukrainian and vice versa
12
+ - **Fuzzy entry detection** — flags entries with the fuzzy flag that need review
13
+ - **Obsolete entry detection** — flags obsolete entries that should be removed
14
+ - **Untranslated entry detection** — flags missing translations, auto-detects source language
12
15
  - **Shifted entry detection** — finds translations that got shifted to the wrong msgid
13
16
  - **Garbled text detection** — catches corrupted/broken unicode
14
17
  - **Ignore rules** — `.po-lint-ignore` file with language scoping and msgctxt support
18
+ - **Configurable checks** — disable individual checks via `pyproject.toml` or CLI
15
19
 
16
20
  ## Installation
17
21
 
@@ -53,6 +57,9 @@ po-lint locale/ --min-detection-length 25
53
57
 
54
58
  # Specify source language (default: en)
55
59
  po-lint locale/ --source-language en
60
+
61
+ # Disable specific checks
62
+ po-lint locale/ --disable untranslated fuzzy
56
63
  ```
57
64
 
58
65
  ## Configuration
@@ -85,6 +92,10 @@ min_text_length = 3
85
92
  # Use compact fastText model instead of full
86
93
  compact_model = false
87
94
 
95
+ # Disable specific checks
96
+ # Valid: wrong_language, wrong_script, shifted_entry, garbled_text, untranslated, fuzzy, obsolete
97
+ disable = []
98
+
88
99
  # Regex patterns to ignore (matched against msgid and msgstr)
89
100
  ignore_patterns = []
90
101
  ```
@@ -109,11 +120,14 @@ screening status::Some msgid
109
120
 
110
121
  ## How it works
111
122
 
112
- 1. **Wrong script check** — fast, no model needed. Checks if the translation uses the expected writing system.
113
- 2. **Distinctive character check** — detects cross-contamination between languages sharing a script (e.g. Russian/Ukrainian).
114
- 3. **Garbled text check** — flags corrupted unicode.
115
- 4. **Shifted entry check** — flags suspiciously short translations for long source strings.
116
- 5. **Wrong language check** — uses fastText with three layers of false positive prevention:
123
+ 1. **Fuzzy entry check** — flags entries marked as fuzzy that need review.
124
+ 2. **Obsolete entry check** — flags obsolete entries that should be removed.
125
+ 3. **Untranslated entry check** — flags entries with empty `msgstr`. The source language is auto-detected (the locale where all entries are untranslated) or can be set explicitly. Skipped for the source language.
126
+ 4. **Wrong script check** — fast, no model needed. Checks if the translation uses the expected writing system.
127
+ 5. **Distinctive character check** — detects cross-contamination between languages sharing a script (e.g. Russian/Ukrainian).
128
+ 6. **Garbled text check** — flags corrupted unicode.
129
+ 7. **Shifted entry check** — flags suspiciously short translations for long source strings.
130
+ 8. **Wrong language check** — uses fastText with three layers of false positive prevention:
117
131
  - **Confused language score merging** — redistributes scores from commonly confused languages (e.g. Danish/Norwegian, Portuguese/Spanish)
118
132
  - **Source language allowance** — borrowed words from the source language are common and allowed
119
133
  - **Carrier phrase confirmation** — re-tests with a language-specific phrase prepended to distinguish false positives from real contamination
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "python-po-lint"
3
- version = "0.1.1"
3
+ dynamic = ["version"]
4
4
  description = "Lint .po translation files for contamination, wrong languages, shifts, and garbled text"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -18,9 +18,15 @@ dependencies = [
18
18
  po-lint = "po_lint.cli:main"
19
19
 
20
20
  [build-system]
21
- requires = ["hatchling"]
21
+ requires = ["hatchling", "hatch-vcs"]
22
22
  build-backend = "hatchling.build"
23
23
 
24
+ [tool.hatch.version]
25
+ source = "vcs"
26
+
27
+ [tool.hatch.build.hooks.vcs]
28
+ version-file = "src/po_lint/_version.py"
29
+
24
30
  [tool.hatch.build.targets.wheel]
25
31
  packages = ["src/po_lint"]
26
32
 
@@ -0,0 +1,34 @@
1
+ # file generated by setuptools-scm
2
+ # don't change, don't track in version control
3
+
4
+ __all__ = [
5
+ "__version__",
6
+ "__version_tuple__",
7
+ "version",
8
+ "version_tuple",
9
+ "__commit_id__",
10
+ "commit_id",
11
+ ]
12
+
13
+ TYPE_CHECKING = False
14
+ if TYPE_CHECKING:
15
+ from typing import Tuple
16
+ from typing import Union
17
+
18
+ VERSION_TUPLE = Tuple[Union[int, str], ...]
19
+ COMMIT_ID = Union[str, None]
20
+ else:
21
+ VERSION_TUPLE = object
22
+ COMMIT_ID = object
23
+
24
+ version: str
25
+ __version__: str
26
+ __version_tuple__: VERSION_TUPLE
27
+ version_tuple: VERSION_TUPLE
28
+ commit_id: COMMIT_ID
29
+ __commit_id__: COMMIT_ID
30
+
31
+ __version__ = version = '0.2.0'
32
+ __version_tuple__ = version_tuple = (0, 2, 0)
33
+
34
+ __commit_id__ = commit_id = None
@@ -17,6 +17,8 @@ class IssueType(Enum):
17
17
  SHIFTED_ENTRY = "shifted_entry"
18
18
  GARBLED_TEXT = "garbled_text"
19
19
  UNTRANSLATED = "untranslated"
20
+ FUZZY = "fuzzy"
21
+ OBSOLETE = "obsolete"
20
22
 
21
23
 
22
24
  @dataclass
@@ -14,7 +14,8 @@ from po_lint.linter import lint_locale_dir
14
14
  def main(argv: list[str] | None = None) -> int:
15
15
  parser = argparse.ArgumentParser(
16
16
  prog="po-lint",
17
- description="Lint .po translation files for contamination, wrong languages, shifts, and garbled text.",
17
+ description="Lint .po translation files for contamination, wrong languages, shifts, and garbled text. "
18
+ "Place a .po-lint-ignore file in the locale/ directory to suppress false positives.",
18
19
  )
19
20
  parser.add_argument(
20
21
  "paths",
@@ -51,6 +52,13 @@ def main(argv: list[str] | None = None) -> int:
51
52
  default=None,
52
53
  help="Minimum cleaned text length for language detection (default: 30).",
53
54
  )
55
+ parser.add_argument(
56
+ "--disable",
57
+ nargs="*",
58
+ default=None,
59
+ help="Disable specific checks (e.g. --disable untranslated fuzzy). "
60
+ "Valid checks: wrong_language, wrong_script, shifted_entry, garbled_text, untranslated, fuzzy, obsolete.",
61
+ )
54
62
  parser.add_argument(
55
63
  "--compact-model",
56
64
  action="store_true",
@@ -86,6 +94,7 @@ def main(argv: list[str] | None = None) -> int:
86
94
  args.min_detection_length if args.min_detection_length is not None
87
95
  else config.min_detection_length
88
96
  )
97
+ disable = args.disable if args.disable is not None else config.disable
89
98
 
90
99
  # Resolve locale directories
91
100
  if args.paths:
@@ -117,6 +126,7 @@ def main(argv: list[str] | None = None) -> int:
117
126
  min_text_length=config.min_text_length,
118
127
  min_detection_length=min_detection_length,
119
128
  ignore_patterns=config.ignore_patterns,
129
+ disable=disable,
120
130
  )
121
131
  all_issues.extend(issues)
122
132
 
@@ -27,6 +27,7 @@ class Config:
27
27
  min_detection_length: int = 30
28
28
  ignore_patterns: list[str] = field(default_factory=list)
29
29
  compact_model: bool = False
30
+ disable: list[str] = field(default_factory=list)
30
31
 
31
32
  def resolve_locale_dirs(self, base_dir: Path) -> list[Path]:
32
33
  """Resolve all locale directories from paths and packages.
@@ -91,4 +92,5 @@ def load_config(project_dir: Path | None = None) -> Config:
91
92
  min_detection_length=tool_config.get("min_detection_length", 30),
92
93
  ignore_patterns=tool_config.get("ignore_patterns", []),
93
94
  compact_model=tool_config.get("compact_model", False),
95
+ disable=tool_config.get("disable", []),
94
96
  )
@@ -1,5 +1,6 @@
1
1
  """Main linter that ties all checks together and walks locale directories."""
2
2
 
3
+ import logging
3
4
  import re
4
5
  from dataclasses import dataclass
5
6
  from pathlib import Path
@@ -16,6 +17,8 @@ from po_lint.checks import (
16
17
  )
17
18
  from po_lint.detector import DEFAULT_MIN_DETECTION_LENGTH, is_wrong_language
18
19
 
20
+ log = logging.getLogger(__name__)
21
+
19
22
  IGNORE_FILE = ".po-lint-ignore"
20
23
 
21
24
 
@@ -115,6 +118,7 @@ def lint_po_file(
115
118
  min_detection_length: int = DEFAULT_MIN_DETECTION_LENGTH,
116
119
  ignore_patterns: list[str] | None = None,
117
120
  ignore_rules: list[IgnoreRule] | None = None,
121
+ disable: list[str] | None = None,
118
122
  ) -> list[Issue]:
119
123
  """Lint a single .po file and return all issues found."""
120
124
  if locale is None:
@@ -124,6 +128,7 @@ def lint_po_file(
124
128
 
125
129
  compiled_ignores = [re.compile(p) for p in (ignore_patterns or [])]
126
130
  ignore_rules = ignore_rules or []
131
+ disabled = set(disable or [])
127
132
 
128
133
  try:
129
134
  catalog = polib.pofile(str(po_file))
@@ -142,6 +147,53 @@ def lint_po_file(
142
147
 
143
148
  issues = []
144
149
 
150
+ # Check for untranslated entries (skip source language)
151
+ if "untranslated" not in disabled and locale != source_language:
152
+ for entry in catalog.untranslated_entries():
153
+ if entry.obsolete:
154
+ continue
155
+ issues.append(
156
+ Issue(
157
+ file=str(po_file),
158
+ line=entry.linenum,
159
+ msgid=entry.msgid,
160
+ msgstr="",
161
+ issue_type=IssueType.UNTRANSLATED,
162
+ severity=Severity.WARNING,
163
+ message="Missing translation",
164
+ )
165
+ )
166
+
167
+ # Check for fuzzy entries
168
+ if "fuzzy" not in disabled:
169
+ for entry in catalog.fuzzy_entries():
170
+ issues.append(
171
+ Issue(
172
+ file=str(po_file),
173
+ line=entry.linenum,
174
+ msgid=entry.msgid,
175
+ msgstr=entry.msgstr,
176
+ issue_type=IssueType.FUZZY,
177
+ severity=Severity.ERROR,
178
+ message="Fuzzy entry — needs review and removal of fuzzy flag",
179
+ )
180
+ )
181
+
182
+ # Check for obsolete entries
183
+ if "obsolete" not in disabled:
184
+ for entry in catalog.obsolete_entries():
185
+ issues.append(
186
+ Issue(
187
+ file=str(po_file),
188
+ line=entry.linenum,
189
+ msgid=entry.msgid,
190
+ msgstr=entry.msgstr,
191
+ issue_type=IssueType.OBSOLETE,
192
+ severity=Severity.ERROR,
193
+ message="Obsolete entry — should be removed",
194
+ )
195
+ )
196
+
145
197
  for entry in catalog.translated_entries():
146
198
  msgid = entry.msgid
147
199
  msgstr = entry.msgstr
@@ -167,49 +219,53 @@ def lint_po_file(
167
219
  continue
168
220
 
169
221
  # 1. Wrong script check (fast, no model needed)
170
- issue = check_wrong_script(msgstr, locale)
171
- if issue:
172
- issue.file = str(po_file)
173
- issue.line = entry.linenum
174
- issue.msgid = msgid
175
- issues.append(issue)
176
- continue # If wrong script, skip language detection (it would also flag)
222
+ if "wrong_script" not in disabled:
223
+ issue = check_wrong_script(msgstr, locale)
224
+ if issue:
225
+ issue.file = str(po_file)
226
+ issue.line = entry.linenum
227
+ issue.msgid = msgid
228
+ issues.append(issue)
229
+ continue # If wrong script, skip language detection (it would also flag)
177
230
 
178
231
  # 2. Garbled text check
179
- issue = check_garbled_text(msgstr)
180
- if issue:
181
- issue.file = str(po_file)
182
- issue.line = entry.linenum
183
- issue.msgid = msgid
184
- issues.append(issue)
185
- continue
232
+ if "garbled_text" not in disabled:
233
+ issue = check_garbled_text(msgstr)
234
+ if issue:
235
+ issue.file = str(po_file)
236
+ issue.line = entry.linenum
237
+ issue.msgid = msgid
238
+ issues.append(issue)
239
+ continue
186
240
 
187
241
  # 3. Shifted entry check
188
- issue = check_shifted_entry(msgid, msgstr)
189
- if issue:
190
- issue.file = str(po_file)
191
- issue.line = entry.linenum
192
- issues.append(issue)
242
+ if "shifted_entry" not in disabled:
243
+ issue = check_shifted_entry(msgid, msgstr)
244
+ if issue:
245
+ issue.file = str(po_file)
246
+ issue.line = entry.linenum
247
+ issues.append(issue)
193
248
 
194
249
  # 4. Wrong language check (uses fastText)
195
- is_wrong, detected_lang, confidence = is_wrong_language(
196
- msgstr, locale, confidence_threshold, source_language, msgid=msgid,
197
- min_detection_length=min_detection_length,
198
- )
199
- if is_wrong:
200
- issues.append(
201
- Issue(
202
- file=str(po_file),
203
- line=entry.linenum,
204
- msgid=msgid,
205
- msgstr=msgstr,
206
- issue_type=IssueType.WRONG_LANGUAGE,
207
- severity=Severity.ERROR,
208
- message=f"Expected {locale}, detected {detected_lang} (confidence: {confidence:.0%})",
209
- detected_lang=detected_lang,
210
- confidence=confidence,
211
- )
250
+ if "wrong_language" not in disabled:
251
+ is_wrong, detected_lang, confidence = is_wrong_language(
252
+ msgstr, locale, confidence_threshold, source_language, msgid=msgid,
253
+ min_detection_length=min_detection_length,
212
254
  )
255
+ if is_wrong:
256
+ issues.append(
257
+ Issue(
258
+ file=str(po_file),
259
+ line=entry.linenum,
260
+ msgid=msgid,
261
+ msgstr=msgstr,
262
+ issue_type=IssueType.WRONG_LANGUAGE,
263
+ severity=Severity.ERROR,
264
+ message=f"Expected {locale}, detected {detected_lang} (confidence: {confidence:.0%})",
265
+ detected_lang=detected_lang,
266
+ confidence=confidence,
267
+ )
268
+ )
213
269
 
214
270
  return issues
215
271
 
@@ -231,6 +287,47 @@ def _is_non_linguistic(text: str) -> bool:
231
287
  return len(cleaned) < 3
232
288
 
233
289
 
290
+ def detect_source_language(locale_dir: Path) -> str | None:
291
+ """Auto-detect the source language from a locale directory.
292
+
293
+ A locale is the source language if:
294
+ - It has .po files with at least one entry
295
+ - ALL entries across ALL its .po files are untranslated (empty msgstr)
296
+ - Exactly one locale in the directory matches this condition
297
+
298
+ Returns the locale code if exactly one match, None otherwise.
299
+ """
300
+ # Collect per-locale stats: (total_entries, total_untranslated)
301
+ locale_stats: dict[str, tuple[int, int]] = {}
302
+
303
+ for po_file in sorted(locale_dir.rglob("*.po")):
304
+ locale = extract_locale_from_path(po_file)
305
+ if locale is None:
306
+ continue
307
+ try:
308
+ catalog = polib.pofile(str(po_file))
309
+ except (OSError, SyntaxError):
310
+ continue
311
+
312
+ total = len(catalog.translated_entries()) + len(catalog.untranslated_entries())
313
+ untranslated = len(catalog.untranslated_entries())
314
+
315
+ prev_total, prev_untranslated = locale_stats.get(locale, (0, 0))
316
+ locale_stats[locale] = (prev_total + total, prev_untranslated + untranslated)
317
+
318
+ # Find locales where every entry is untranslated (and there are entries)
319
+ candidates = [
320
+ loc for loc, (total, untranslated) in locale_stats.items()
321
+ if total > 0 and total == untranslated
322
+ ]
323
+
324
+ if len(candidates) == 1:
325
+ log.debug("Auto-detected source language: %s", candidates[0])
326
+ return candidates[0]
327
+
328
+ return None
329
+
330
+
234
331
  def lint_locale_dir(
235
332
  locale_dir: Path,
236
333
  languages: list[str] | None = None,
@@ -239,6 +336,7 @@ def lint_locale_dir(
239
336
  min_text_length: int = 3,
240
337
  min_detection_length: int = DEFAULT_MIN_DETECTION_LENGTH,
241
338
  ignore_patterns: list[str] | None = None,
339
+ disable: list[str] | None = None,
242
340
  ) -> list[Issue]:
243
341
  """Lint all .po files in a locale directory.
244
342
 
@@ -251,8 +349,14 @@ def lint_locale_dir(
251
349
  confidence_threshold: Minimum confidence to flag a wrong language.
252
350
  min_text_length: Minimum msgstr length to check.
253
351
  ignore_patterns: Regex patterns for msgid/msgstr to skip.
352
+ disable: List of check names to disable (e.g. ["untranslated", "fuzzy"]).
254
353
  """
255
354
  ignore_rules = load_ignore_rules(locale_dir)
355
+
356
+ # Auto-detect source language as fallback
357
+ detected_source = detect_source_language(locale_dir)
358
+ effective_source = detected_source or source_language
359
+
256
360
  issues = []
257
361
 
258
362
  for po_file in sorted(locale_dir.rglob("*.po")):
@@ -265,12 +369,13 @@ def lint_locale_dir(
265
369
  file_issues = lint_po_file(
266
370
  po_file,
267
371
  locale=locale,
268
- source_language=source_language,
372
+ source_language=effective_source,
269
373
  confidence_threshold=confidence_threshold,
270
374
  min_text_length=min_text_length,
271
375
  min_detection_length=min_detection_length,
272
376
  ignore_patterns=ignore_patterns,
273
377
  ignore_rules=ignore_rules,
378
+ disable=disable,
274
379
  )
275
380
  issues.extend(file_issues)
276
381
 
@@ -0,0 +1,20 @@
1
+ # Danish translations — includes fuzzy and obsolete entries for testing
2
+ msgid ""
3
+ msgstr ""
4
+ "Content-Type: text/plain; charset=UTF-8\n"
5
+ "Language: da\n"
6
+ "Plural-Forms: nplurals=2; plural=(n != 1);\n"
7
+
8
+ msgid "Welcome"
9
+ msgstr "Velkommen"
10
+
11
+ #, fuzzy
12
+ #| msgid "Save"
13
+ msgid "Save changes"
14
+ msgstr "Gem"
15
+
16
+ msgid "Cancel"
17
+ msgstr "Annuller"
18
+
19
+ #~ msgid "Old removed string"
20
+ #~ msgstr "Gammel fjernet streng"
@@ -58,3 +58,15 @@ class TestLoadConfig:
58
58
  assert config.confidence_threshold == 0.7
59
59
  assert config.min_text_length == 5
60
60
  assert config.ignore_patterns == ["^TODO"]
61
+
62
+ def test_pyproject_with_disable(self, tmp_path):
63
+ (tmp_path / "pyproject.toml").write_text(
64
+ '[tool.po-lint]\n'
65
+ 'disable = ["untranslated", "fuzzy"]\n'
66
+ )
67
+ config = load_config(tmp_path)
68
+ assert config.disable == ["untranslated", "fuzzy"]
69
+
70
+ def test_disable_defaults_to_empty(self):
71
+ config = Config()
72
+ assert config.disable == []
@@ -2,11 +2,13 @@
2
2
 
3
3
  from pathlib import Path
4
4
 
5
+ from po_lint.checks import IssueType
5
6
  from po_lint.linter import (
6
7
  IgnoreRule,
7
8
  _is_ignored,
8
9
  _is_non_linguistic,
9
10
  extract_locale_from_path,
11
+ lint_po_file,
10
12
  load_ignore_rules,
11
13
  )
12
14
 
@@ -134,3 +136,50 @@ class TestIsIgnored:
134
136
  """A rule without context should match entries with or without context."""
135
137
  assert _is_ignored("Cancel", "some_ctx", "nl", self.rules) is True
136
138
  assert _is_ignored("Cancel", None, "nl", self.rules) is True
139
+
140
+
141
+ DA_FIXTURE = FIXTURES_DIR / "da" / "LC_MESSAGES" / "django.po"
142
+
143
+
144
+ class TestFuzzyDetection:
145
+ def test_fuzzy_entries_are_errors(self):
146
+ issues = lint_po_file(DA_FIXTURE, locale="da")
147
+ fuzzy_issues = [i for i in issues if i.issue_type == IssueType.FUZZY]
148
+ assert len(fuzzy_issues) == 1
149
+ assert fuzzy_issues[0].msgid == "Save changes"
150
+
151
+ def test_fuzzy_severity_is_error(self):
152
+ issues = lint_po_file(DA_FIXTURE, locale="da")
153
+ fuzzy_issues = [i for i in issues if i.issue_type == IssueType.FUZZY]
154
+ assert all(i.severity.value == "error" for i in fuzzy_issues)
155
+
156
+
157
+ class TestObsoleteDetection:
158
+ def test_obsolete_entries_are_errors(self):
159
+ issues = lint_po_file(DA_FIXTURE, locale="da")
160
+ obsolete_issues = [i for i in issues if i.issue_type == IssueType.OBSOLETE]
161
+ assert len(obsolete_issues) == 1
162
+ assert obsolete_issues[0].msgid == "Old removed string"
163
+
164
+ def test_obsolete_severity_is_error(self):
165
+ issues = lint_po_file(DA_FIXTURE, locale="da")
166
+ obsolete_issues = [i for i in issues if i.issue_type == IssueType.OBSOLETE]
167
+ assert all(i.severity.value == "error" for i in obsolete_issues)
168
+
169
+
170
+ class TestDisable:
171
+ def test_disable_fuzzy(self):
172
+ issues = lint_po_file(DA_FIXTURE, locale="da", disable=["fuzzy"])
173
+ assert not any(i.issue_type == IssueType.FUZZY for i in issues)
174
+
175
+ def test_disable_obsolete(self):
176
+ issues = lint_po_file(DA_FIXTURE, locale="da", disable=["obsolete"])
177
+ assert not any(i.issue_type == IssueType.OBSOLETE for i in issues)
178
+
179
+ def test_disable_multiple(self):
180
+ issues = lint_po_file(DA_FIXTURE, locale="da", disable=["fuzzy", "obsolete"])
181
+ assert not any(i.issue_type in (IssueType.FUZZY, IssueType.OBSOLETE) for i in issues)
182
+
183
+ def test_disable_untranslated(self):
184
+ issues = lint_po_file(DA_FIXTURE, locale="da", disable=["untranslated"])
185
+ assert not any(i.issue_type == IssueType.UNTRANSLATED for i in issues)
@@ -313,7 +313,7 @@ wheels = [
313
313
 
314
314
  [[package]]
315
315
  name = "python-po-lint"
316
- version = "0.1.0"
316
+ version = "0.1.1"
317
317
  source = { editable = "." }
318
318
  dependencies = [
319
319
  { name = "fasttext-wheel" },
@@ -1,201 +0,0 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
- exercising permissions granted by this License.
25
-
26
- "Source" form shall mean the preferred form for making modifications,
27
- including but not limited to software source code, documentation
28
- source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical
31
- transformation or translation of a Source form, including but
32
- not limited to compiled object code, generated documentation,
33
- and conversions to other media types.
34
-
35
- "Work" shall mean the work of authorship, whether in Source or
36
- Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work
38
- (an example is provided in the Appendix below).
39
-
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
- form, that is based on (or derived from) the Work and for which the
42
- editorial revisions, annotations, elaborations, or other modifications
43
- represent, as a whole, an original work of authorship. For the purposes
44
- of this License, Derivative Works shall not include works that remain
45
- separable from, or merely link (or bind by name) to the interfaces of,
46
- the Work and Derivative Works thereof.
47
-
48
- "Contribution" shall mean any work of authorship, including
49
- the original version of the Work and any modifications or additions
50
- to that Work or Derivative Works thereof, that is intentionally
51
- submitted to Licensor for inclusion in the Work by the copyright owner
52
- or by an individual or Legal Entity authorized to submit on behalf of
53
- the copyright owner. For the purposes of this definition, "submitted"
54
- means any form of electronic, verbal, or written communication sent
55
- to the Licensor or its representatives, including but not limited to
56
- communication on electronic mailing lists, source code control systems,
57
- and issue tracking systems that are managed by, or on behalf of, the
58
- Licensor for the purpose of discussing and improving the Work, but
59
- excluding communication that is conspicuously marked or otherwise
60
- designated in writing by the copyright owner as "Not a Contribution."
61
-
62
- "Contributor" shall mean Licensor and any individual or Legal Entity
63
- on behalf of whom a Contribution has been received by Licensor and
64
- subsequently incorporated within the Work.
65
-
66
- 2. Grant of Copyright License. Subject to the terms and conditions of
67
- this License, each Contributor hereby grants to You a perpetual,
68
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
- copyright license to reproduce, prepare Derivative Works of,
70
- publicly display, publicly perform, sublicense, and distribute the
71
- Work and such Derivative Works in Source or Object form.
72
-
73
- 3. Grant of Patent License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- (except as stated in this section) patent license to make, have made,
77
- use, offer to sell, sell, import, and otherwise transfer the Work,
78
- where such license applies only to those patent claims licensable
79
- by such Contributor that are necessarily infringed by their
80
- Contribution(s) alone or by combination of their Contribution(s)
81
- with the Work to which such Contribution(s) was submitted. If You
82
- institute patent litigation against any entity (including a
83
- cross-claim or counterclaim in a lawsuit) alleging that the Work
84
- or a Contribution incorporated within the Work constitutes direct
85
- or contributory patent infringement, then any patent licenses
86
- granted to You under this License for that Work shall terminate
87
- as of the date such litigation is filed.
88
-
89
- 4. Redistribution. You may reproduce and distribute copies of the
90
- Work or Derivative Works thereof in any medium, with or without
91
- modifications, and in Source or Object form, provided that You
92
- meet the following conditions:
93
-
94
- (a) You must give any other recipients of the Work or
95
- Derivative Works a copy of this License; and
96
-
97
- (b) You must cause any modified files to carry prominent notices
98
- stating that You changed the files; and
99
-
100
- (c) You must retain, in the Source form of any Derivative Works
101
- that You distribute, all copyright, patent, trademark, and
102
- attribution notices from the Source form of the Work,
103
- excluding those notices that do not pertain to any part of
104
- the Derivative Works; and
105
-
106
- (d) If the Work includes a "NOTICE" text file as part of its
107
- distribution, then any Derivative Works that You distribute must
108
- include a readable copy of the attribution notices contained
109
- within such NOTICE file, excluding those notices that do not
110
- pertain to any part of the Derivative Works, in at least one
111
- of the following places: within a NOTICE text file distributed
112
- as part of the Derivative Works; within the Source form or
113
- documentation, if provided along with the Derivative Works; or,
114
- within a display generated by the Derivative Works, if and
115
- wherever such third-party notices normally appear. The contents
116
- of the NOTICE file are for informational purposes only and
117
- do not modify the License. You may add Your own attribution
118
- notices within Derivative Works that You distribute, alongside
119
- or as an addendum to the NOTICE text from the Work, provided
120
- that such additional attribution notices cannot be construed
121
- as modifying the License.
122
-
123
- You may add Your own copyright statement to Your modifications and
124
- may provide additional or different license terms and conditions
125
- for use, reproduction, or distribution of Your modifications, or
126
- for any such Derivative Works as a whole, provided Your use,
127
- reproduction, and distribution of the Work otherwise complies with
128
- the conditions stated in this License.
129
-
130
- 5. Submission of Contributions. Unless You explicitly state otherwise,
131
- any Contribution intentionally submitted for inclusion in the Work
132
- by You to the Licensor shall be under the terms and conditions of
133
- this License, without any additional terms or conditions.
134
- Notwithstanding the above, nothing herein shall supersede or modify
135
- the terms of any separate license agreement you may have executed
136
- with Licensor regarding such Contributions.
137
-
138
- 6. Trademarks. This License does not grant permission to use the trade
139
- names, trademarks, service marks, or product names of the Licensor,
140
- except as required for reasonable and customary use in describing the
141
- origin of the Work and reproducing the content of the NOTICE file.
142
-
143
- 7. Disclaimer of Warranty. Unless required by applicable law or
144
- agreed to in writing, Licensor provides the Work (and each
145
- Contributor provides its Contributions) on an "AS IS" BASIS,
146
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
- implied, including, without limitation, any warranties or conditions
148
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
- PARTICULAR PURPOSE. You are solely responsible for determining the
150
- appropriateness of using or redistributing the Work and assume any
151
- risks associated with Your exercise of permissions under this License.
152
-
153
- 8. Limitation of Liability. In no event and under no legal theory,
154
- whether in tort (including negligence), contract, or otherwise,
155
- unless required by applicable law (such as deliberate and grossly
156
- negligent acts) or agreed to in writing, shall any Contributor be
157
- liable to You for damages, including any direct, indirect, special,
158
- incidental, or consequential damages of any character arising as a
159
- result of this License or out of the use or inability to use the
160
- Work (including but not limited to damages for loss of goodwill,
161
- work stoppage, computer failure or malfunction, or any and all
162
- other commercial damages or losses), even if such Contributor
163
- has been advised of the possibility of such damages.
164
-
165
- 9. Accepting Warranty or Additional Liability. While redistributing
166
- the Work or Derivative Works thereof, You may choose to offer,
167
- and charge a fee for, acceptance of support, warranty, indemnity,
168
- or other liability obligations and/or rights consistent with this
169
- License. However, in accepting such obligations, You may act only
170
- on Your own behalf and on Your sole responsibility, not on behalf
171
- of any other Contributor, and only if You agree to indemnify,
172
- defend, and hold each Contributor harmless for any liability
173
- incurred by, or claims asserted against, such Contributor by reason
174
- of your accepting any such warranty or additional liability.
175
-
176
- END OF TERMS AND CONDITIONS
177
-
178
- APPENDIX: How to apply the Apache License to your work.
179
-
180
- To apply the Apache License to your work, attach the following
181
- boilerplate notice, with the fields enclosed by brackets "[]"
182
- replaced with your own identifying information. (Don't include
183
- the brackets!) The text should be enclosed in the appropriate
184
- comment syntax for the file format. We also recommend that a
185
- file or class name and description of purpose be included on the
186
- same "printed page" as the copyright notice for easier
187
- identification within third-party archives.
188
-
189
- Copyright [yyyy] [name of copyright owner]
190
-
191
- Licensed under the Apache License, Version 2.0 (the "License");
192
- you may not use this file except in compliance with the License.
193
- You may obtain a copy of the License at
194
-
195
- http://www.apache.org/licenses/LICENSE-2.0
196
-
197
- Unless required by applicable law or agreed to in writing, software
198
- distributed under the License is distributed on an "AS IS" BASIS,
199
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
- See the License for the specific language governing permissions and
201
- limitations under the License.