@@ -0,0 +1,2534 @@
+# -*- coding: utf-8 -*-%0A%22%22%22%0AContains classes to help manage multi-language pages.%0A%22%22%22%0A%0Afrom hyde.plugin import Plugin%0A%0Aclass LanguagePlugin(Plugin):%0A    %22%22%22%0A    Each page should be tagged with a language using %60language%60 meta%0A    data. Each page should also have an UUID stored in %60uuid%60 meta%0A    data. Pages with different languages but the same UUID will be%0A    considered a translation of each other.%0A%0A    For example, consider that you have the following content tree:%0A       - %60en/%60%0A       - %60fr/%60%0A%0A    In %60en/meta.yaml%60, you set %60language: en%60 and in %60fr/meta.yaml%60, you%0A    set %60language: fr%60. In %60en/my-first-page.html%60, you put something like%0A    this::%0A         -------%0A         uuid: page1%0A         -------%0A         My first page%0A%0A     And in %60fr/ma-premiere-page.html%60, you put something like this::%0A         -------%0A         uuid: page1%0A         -------%0A         Ma premi%C3%A8re page%0A%0A    You'll get a %60translations%60 attribute attached to the resource%0A    with the list of resources that are a translation of this one.%0A    %22%22%22%0A%0A    def __init__(self, site):%0A        super(LanguagePlugin, self).__init__(site)%0A        self.languages = %7B%7D # Associate a UUID to the list of resources available%0A%0A    def begin_site(self):%0A        %22%22%22%0A        Initialize plugin. Build the language tree for each node%0A        %22%22%22%0A        # Build association between UUID and list of resources%0A        for node in self.site.content.walk():%0A            for resource in node.resources:%0A                try:%0A                    uuid = resource.meta.uuid%0A                    language = resource.meta.language%0A                except AttributeError:%0A                    continue%0A                if uuid not in self.languages:%0A                    self.languages%5Buuid%5D = %5B%5D%0A                self.languages%5Buuid%5D.append(resource)%0A        # Add back the information about other languages%0A        for uuid, resources in self.languages.items():%0A            for resource in resources:%0A                language = resource.meta.language%0A                resource.translations = %5C%0A                    %5Br for r in resources%0A                     if r.meta.language != language%5D%0A                translations = %22,%22.join(%5Bt.meta.language for t in resource.translations%5D)%0A                self.logger.debug(%0A                    %22Adding translations for resource %5B%25s%5D from %25s to %25s%22 %25 (resource,%0A                                                                             language,%0A                                                                             translations))%0A

Add a language plugin.