def locale_directory_paths(self): """ A map of locale codes and their absolute directory paths. Create locale directory, if not in repository yet. """ locale_directory_paths = {} parent_directories = set() for locale in self.locales: try: if self.configuration: locale_directory_paths[locale.code] = self.configuration.l10n_base else: locale_directory_paths[locale.code] = locale_directory_path( self.checkout_path, locale.code, parent_directories, ) parent_directory = get_parent_directory(locale_directory_paths[locale.code]) except IOError: if not self.db_project.has_multi_locale_repositories: source_directory = self.source_directory_path parent_directory = get_parent_directory(source_directory) locale_code = locale.code if uses_undercore_as_separator(parent_directory): locale_code = locale_code.replace('-', '_') locale_directory = os.path.join(parent_directory, locale_code) # For asymmetric formats, create empty folder if is_asymmetric_resource(next(self.relative_resource_paths())): os.makedirs(locale_directory) # For other formats, copy resources from source directory else: shutil.copytree(source_directory, locale_directory) for root, dirnames, filenames in scandir.walk(locale_directory): for filename in filenames: path = os.path.join(root, filename) if is_resource(filename): os.rename(path, source_to_locale_path(path)) else: os.remove(path) locale_directory_paths[locale.code] = locale_directory else: raise MissingLocaleDirectoryError( 'Directory for locale `{0}` not found'.format(locale.code) ) parent_directories.add(parent_directory) return locale_directory_paths
def locale_directory_paths(self): """ A map of locale codes and their absolute directory paths. Create locale directory, if not in repository yet. """ locale_directory_paths = {} parent_directories = set() for locale in self.locales: try: locale_directory_paths[locale.code] = locale_directory_path( self.checkout_path, locale.code, parent_directories) parent_directory = get_parent_directory( locale_directory_paths[locale.code]) except IOError: if not self.db_project.has_multi_locale_repositories: source_directory = self.source_directory_path parent_directory = get_parent_directory(source_directory) locale_code = locale.code if uses_undercore_as_separator(parent_directory): locale_code = locale_code.replace('-', '_') locale_directory = os.path.join(parent_directory, locale_code) # For asymmetric formats, create empty folder if is_asymmetric_resource( next(self.relative_resource_paths())): os.makedirs(locale_directory) # For other formats, copy resources from source directory else: shutil.copytree(source_directory, locale_directory) for root, dirnames, filenames in scandir.walk( locale_directory): for filename in filenames: path = os.path.join(root, filename) if is_resource(filename): os.rename(path, source_to_locale_path(path)) else: os.remove(path) locale_directory_paths[locale.code] = locale_directory else: raise MissingLocaleDirectoryError( 'Directory for locale `{0}` not found'.format( locale.code)) parent_directories.add(parent_directory) return locale_directory_paths