A repository for message catalogs.
| 119 | |
| 120 | |
| 121 | class CatalogRepository: |
| 122 | """A repository for message catalogs.""" |
| 123 | |
| 124 | def __init__( |
| 125 | self, |
| 126 | basedir: str | os.PathLike[str], |
| 127 | locale_dirs: list[str], |
| 128 | language: str, |
| 129 | encoding: str, |
| 130 | ) -> None: |
| 131 | self.basedir = _StrPath(basedir) |
| 132 | self._locale_dirs = locale_dirs |
| 133 | self.language = language |
| 134 | self.encoding = encoding |
| 135 | |
| 136 | @property |
| 137 | def locale_dirs(self) -> Iterator[_StrPath]: |
| 138 | if not self.language: |
| 139 | return |
| 140 | |
| 141 | for locale_dir in self._locale_dirs: |
| 142 | locale_path = self.basedir / locale_dir / self.language / 'LC_MESSAGES' |
| 143 | if locale_path.exists(): |
| 144 | yield self.basedir / locale_dir |
| 145 | else: |
| 146 | logger.verbose(__('locale_dir %s does not exist'), locale_path) |
| 147 | |
| 148 | @property |
| 149 | def pofiles(self) -> Iterator[tuple[_StrPath, _StrPath]]: |
| 150 | for locale_dir in self.locale_dirs: |
| 151 | locale_path = locale_dir / self.language / 'LC_MESSAGES' |
| 152 | for abs_path in locale_path.rglob('*.po'): |
| 153 | rel_path = abs_path.relative_to(locale_path) |
| 154 | # skip dot-directories |
| 155 | if any(part.startswith('.') for part in rel_path.parts[:-1]): |
| 156 | continue |
| 157 | yield locale_path, rel_path |
| 158 | |
| 159 | @property |
| 160 | def catalogs(self) -> Iterator[CatalogInfo]: |
| 161 | for basedir, filename in self.pofiles: |
| 162 | domain = filename.with_suffix('').as_posix() |
| 163 | yield CatalogInfo(basedir, domain, self.encoding) |
| 164 | |
| 165 | |
| 166 | def docname_to_domain(docname: str, compaction: bool | str) -> str: |
no outgoing calls
no test coverage detected
searching dependent graphs…