Return a tuple (contrib name, absolute path) for all locale directories, optionally including the django core catalog. If resources list is not None, filter directories matching resources content.
(resources, include_core=True)
| 143 | |
| 144 | |
| 145 | def _get_locale_dirs(resources, include_core=True): |
| 146 | """ |
| 147 | Return a tuple (contrib name, absolute path) for all locale directories, |
| 148 | optionally including the django core catalog. |
| 149 | If resources list is not None, filter directories matching resources |
| 150 | content. |
| 151 | """ |
| 152 | contrib_dir = os.path.join(os.getcwd(), "django", "contrib") |
| 153 | dirs = [] |
| 154 | |
| 155 | # Collect all locale directories |
| 156 | for contrib_name in os.listdir(contrib_dir): |
| 157 | path = os.path.join(contrib_dir, contrib_name, "locale") |
| 158 | if os.path.isdir(path): |
| 159 | dirs.append((contrib_name, path)) |
| 160 | if contrib_name in HAVE_JS: |
| 161 | dirs.append(("%s-js" % contrib_name, path)) |
| 162 | if include_core: |
| 163 | dirs.insert(0, ("core", os.path.join(os.getcwd(), "django", "conf", "locale"))) |
| 164 | |
| 165 | # Filter by resources, if any |
| 166 | if resources is not None: |
| 167 | res_names = [d[0] for d in dirs] |
| 168 | dirs = [ld for ld in dirs if ld[0] in resources] |
| 169 | if len(resources) > len(dirs): |
| 170 | print( |
| 171 | "You have specified some unknown resources. " |
| 172 | "Available resource names are: %s" % (", ".join(res_names),) |
| 173 | ) |
| 174 | exit(1) |
| 175 | return dirs |
| 176 | |
| 177 | |
| 178 | def _tx_resource_slug_for_name(name): |
no test coverage detected