コード例 #1
0
def create_default_projects():
    """Create the default projects that we host.

    You might want to add your projects here, although you can also add things
    through the web interface later.
    """
    from pootle_project.models import Project

    en = require_english()

    #criteria = {
    #    'code': u"pootle",
    #    'source_language': en,
    #    'fullname': u"Pootle",
    #    'description': ('<div dir="ltr" lang="en">Interface translations for '
    #                    'Pootle.<br />See the <a href="http://'
    #                    'pootle.locamotion.org">official Pootle server</a> '
    #                    'for the translations of Pootle.</div>')
    #    'checkstyle': "standard",
    #    'localfiletype': "po",
    #    'treestyle': "auto",
    #}
    #pootle = Project(**criteria)
    #pootle.save()

    criteria = {
        'code': u"tutorial",
        'source_language': en,
        'fullname': u"Tutorial",
        'checkstyle': "standard",
        'localfiletype': "po",
        'treestyle': "auto",
    }
    tutorial = Project(**criteria)
    tutorial.save()
コード例 #2
0
ファイル: initdb.py プロジェクト: DronRathore/pootle
def create_default_projects():
    """Create the default projects that we host.

    You might want to add your projects here, although you can also add things
    through the web interface later.
    """
    from pootle_app.management import require_english
    from pootle_project.models import Project

    en = require_english()

    #pootle = Project(code=u"pootle", source_language=en)
    #pootle.fullname = u"Pootle"
    #pootle.description = ('<div dir="ltr" lang="en">Interface translations '
    #                      'for Pootle. <br /> See the <a href="http://'
    #                      'pootle.locamotion.org">official Pootle server</a> '
    #                      'for the translations of Pootle.</div>')
    #pootle.checkstyle = "standard"
    #pootle.localfiletype = "po"
    #pootle.treestyle = "auto"
    #pootle.save()

    tutorial = Project(code=u"tutorial", source_language=en)
    tutorial.fullname = u"Tutorial"
    tutorial.description = ('<div dir="ltr" lang="en">Tutorial project where '
                            'users can play with Pootle and learn more about '
                            'translation and localisation.<br />For more help '
                            'on localisation, visit the <a href="http://'
                            'translate.sourceforge.net/wiki/guide/start">'
                            'localisation guide</a>.</div>')
    tutorial.checkstyle = "standard"
    tutorial.localfiletype = "po"
    tutorial.treestyle = "auto"
    tutorial.save()
コード例 #3
0
ファイル: initdb.py プロジェクト: Jobava/pootle
def create_default_projects():
    """Create the default projects that we host.

    You might want to add your projects here, although you can also add things
    through the web interface later.
    """
    from pootle_project.models import Project

    en = require_english()

    criteria = {
        'code': u"tutorial",
        'source_language': en,
        'fullname': u"Tutorial",
        'checkstyle': "standard",
        'localfiletype': "po",
        'treestyle': "auto",
    }
    tutorial = Project(**criteria)
    tutorial.save()

    criteria = {
        'active': True,
        'title': "Project instructions",
        'body': ('<div dir="ltr" lang="en">Tutorial project where users can '
                 'play with Pootle and learn more about translation and '
                 'localisation.<br />For more help on localisation, visit the '
                 '<a href="http://docs.translatehouse.org/projects/'
                 'localization-guide/en/latest/guide/start.html">localisation '
                 'guide</a>.</div>'),
        'virtual_path': "announcements/projects/"+tutorial.code,
    }
    ann = Announcement(**criteria)
    ann.save()
コード例 #4
0
ファイル: views.py プロジェクト: lehaison/wikitrans-pootle
def _source_to_pootle_project(article): 
    import logging
    from django.utils.encoding import smart_str
    from pootle_app.models.signals import post_template_update


    # Fetch the source_language
    sl_set = Language.objects.filter(code=article.language)
    
    if len(sl_set) < 1:
        return False

    source_language = sl_set[0]
        
     # Construct the project
    project = Project()
    project.fullname = u"%s:%s" % (article.language, article.title)
    project.code = project.fullname.replace(" ", "_").replace(":", "_")
    # PO filetype
    #project.localfiletype = "po" # filetype_choices[0]
    
    project.source_language = source_language
  # Save the project
    project.save()
    
    templates_language = Language.objects.filter(code='templates')[0]
    project.add_language(templates_language)
    project.save()
    
    
    #code copied for wr_articles
    logging.debug ( "project saved")
    # Export the article to .po and store in the templates "translation project". This will be used to generate translation requests for other languages.
    templatesProject = project.get_template_translationproject()
    po = article.sentences_to_po()
    poFilePath = "%s/article.pot" % (templatesProject.abs_real_path)
    
    oldstats = templatesProject.getquickstats()
    
    # Write the file
    with open(poFilePath, 'w') as f:
        f.write(smart_str(po.__str__()))
    
    # Force the project to scan for changes.
    templatesProject.scan_files()
    templatesProject.update(conservative=False)
    
    # Log the changes
    newstats = templatesProject.getquickstats()
    post_template_update.send(sender=templatesProject, oldstats=oldstats, newstats=newstats)
        
    
    
    return project
コード例 #5
0
def import_projects(parsed_data):
    # This could prompt the user, asking:
    # "Want us to import projects? Say no if you have already 
    # added the projects to the new Pootle DB in the web UI."

    data = parsed_data.__root__._assignments # Is this really the right way?
    prefix = 'Pootle.projects.'

    # Filter out unrelated keys
    keys = [key for key in data if key.startswith(prefix)]

    # Clean up 'pootle.fullname' into 'pootle'
    projs = set([key[len(prefix):].split('.')[0] for key in keys]) 

    en = require_english()
    for proj in map(lambda s: unicode(s, 'utf-8'), projs):
        # id, for free
        # code:
        try:
            db_proj = Project.objects.get(code=proj)
            logging.log(logging.INFO,
                        'Already found a project named %s.\n'\
                        'Data for this project are not imported.',
                        proj)
            continue
        except Project.DoesNotExist:
            db_proj = Project(code=proj, source_language=en)

        # fullname
        db_proj.fullname = _get_attribute(data, proj, 'fullname', prefix=prefix)

        # description
        db_proj.description = _get_attribute(data, proj, 'description',
                                             prefix=prefix)

        # checkstyle
        db_proj.checkstyle = _get_attribute(data, proj, 'checkerstyle',
                                            unicode_me = False, prefix=prefix)

        # localfiletype
        db_proj.localfiletype = _get_attribute(data, proj, 'localfiletype',
                                               default='po', prefix=prefix)

        # treestyle
        db_proj.treestyle = _get_attribute(data, proj, 'treestyle',
                            unicode_me = False, default='auto', prefix=prefix)

        # ignoredfiles
        db_proj.ignoredfiles = _get_attribute(data, proj, 'ignoredfiles',
                               default=u'', prefix=prefix)

        logging.info("Creating project %s", db_proj)
        db_proj.save()
コード例 #6
0
def import_projects(parsed_data):
    # This could prompt the user, asking:
    # "Want us to import projects? Say no if you have already
    # added the projects to the new Pootle DB in the web UI."

    data = parsed_data.__root__._assignments # Is this really the right way?
    prefix = 'Pootle.projects.'

    # Filter out unrelated keys
    keys = [key for key in data if key.startswith(prefix)]

    # Clean up 'pootle.fullname' into 'pootle'
    projs = set([key[len(prefix):].split('.')[0] for key in keys])

    en = require_english()
    for proj in map(lambda s: unicode(s, 'utf-8'), projs):
        # id, for free
        # code:
        try:
            db_proj = Project.objects.get(code=proj)
            logging.log(logging.INFO,
                        'Already found a project named %s.\n'\
                        'Data for this project are not imported.',
                        proj)
            continue
        except Project.DoesNotExist:
            db_proj = Project(code=proj, source_language=en)

        # fullname
        db_proj.fullname = _get_attribute(data, proj, 'fullname', prefix=prefix)

        # description
        db_proj.description = _get_attribute(data, proj, 'description',
                                             prefix=prefix)

        # checkstyle
        db_proj.checkstyle = _get_attribute(data, proj, 'checkerstyle',
                                            unicode_me=False, prefix=prefix)

        # localfiletype
        db_proj.localfiletype = _get_attribute(data, proj, 'localfiletype',
                                               default='po', prefix=prefix)

        # treestyle
        db_proj.treestyle = _get_attribute(data, proj, 'treestyle',
                            unicode_me=False, default='auto', prefix=prefix)

        # ignoredfiles
        db_proj.ignoredfiles = _get_attribute(data, proj, 'ignoredfiles',
                               default=u'', prefix=prefix)

        logging.info("Creating project %s", db_proj)
        db_proj.save()
コード例 #7
0
ファイル: project.py プロジェクト: arky/pootle
def test_create_project_good(english):
    """Tests projects are created with valid arguments only."""

    proj = Project(code="hello", fullname="world", source_language=english)
    proj.save()
    proj.delete()

    code_with_padding = "  hello  "
    fullname_with_padding = "  world  "

    proj = Project(code=code_with_padding, fullname="world",
                   source_language=english)
    proj.save()
    assert proj.code == code_with_padding.strip()
    proj.delete()

    proj = Project(code="hello", fullname=fullname_with_padding,
                   source_language=english)
    proj.save()
    assert proj.fullname == fullname_with_padding.strip()
    proj.delete()

    proj = Project(code=code_with_padding, fullname=fullname_with_padding,
                   source_language=english)
    proj.save()
    assert proj.code == code_with_padding.strip()
    assert proj.fullname == fullname_with_padding.strip()
    proj.delete()
コード例 #8
0
ファイル: project.py プロジェクト: unasettimana/pootle
def test_create_project_good(english):
    """Tests projects are created with valid arguments only."""

    proj = Project(code="hello", fullname="world", source_language=english)
    proj.save()
    proj.delete()

    code_with_padding = "  hello  "
    fullname_with_padding = "  world  "

    proj = Project(code=code_with_padding, fullname="world",
                   source_language=english)
    proj.save()
    assert proj.code == code_with_padding.strip()
    proj.delete()

    proj = Project(code="hello", fullname=fullname_with_padding,
                   source_language=english)
    proj.save()
    assert proj.fullname == fullname_with_padding.strip()
    proj.delete()

    proj = Project(code=code_with_padding, fullname=fullname_with_padding,
                   source_language=english)
    proj.save()
    assert proj.code == code_with_padding.strip()
    assert proj.fullname == fullname_with_padding.strip()
    proj.delete()
コード例 #9
0
ファイル: models.py プロジェクト: lefterav/wikitrans-pootle
    def notusedsource_to_pootle_project(self):
        """
        Constructs a Pootle project from the article, if a project doesn't already exist.
        """

        logging.debug ( "source_to_pootle_project" )
        from pootle_app.models.signals import post_template_update
        
        if self.pootle_project_exists():
            raise Exception("Project %s already exists!" % self.get_project_name())
        
        # Fetch the source_language
        sl_set = Language.objects.filter(code = self.language)
        
        if len(sl_set) < 1:
            raise Exception("Language code %s does not exist!" % self.language)
        
        source_language = sl_set[0]
        logging.debug ( "source language" +  source_language )
        # Construct the project
        project = Project()
        project.fullname = self.get_project_name()
        project.code = self.get_project_code()
        project.source_language = source_language
        
        # Save the project
        project.save()
        logging.debug ( "project saved")
        # Export the article to .po and store in the templates "translation project". This will be used to generate translation requests for other languages.
        templatesProject = project.get_template_translationproject()
        po = self.sentences_to_po()
        poFilePath = "%s/article.pot" % (templatesProject.abs_real_path)
        
        oldstats = templatesProject.getquickstats()
        
        # Write the file
        with open(poFilePath, 'w') as f:
            f.write(po.__str__())
        
        # Force the project to scan for changes.
        templatesProject.scan_files()
        templatesProject.update(conservative=False)
        
        # Log the changes
        newstats = templatesProject.getquickstats()
        post_template_update.send(sender=templatesProject, oldstats=oldstats, newstats=newstats)
        
        return project
コード例 #10
0
def create_default_projects():
    """Create the default projects that we host.

    You might want to add your projects here, although you can also add things
    through the web interface later.
    """
    from pootle_app.management import require_english
    from pootle_project.models import Project

    en = require_english()

    #criteria = {
    #    'code': u"pootle",
    #    'source_language': en,
    #    'fullname': u"Pootle",
    #    'description': ('<div dir="ltr" lang="en">Interface translations for '
    #                    'Pootle.<br />See the <a href="http://'
    #                    'pootle.locamotion.org">official Pootle server</a> '
    #                    'for the translations of Pootle.</div>')
    #    'checkstyle': "standard",
    #    'localfiletype': "po",
    #    'treestyle': "auto",
    #}
    #pootle = Project(**criteria)
    #pootle.save()

    criteria = {
        'code':
        u"tutorial",
        'source_language':
        en,
        'fullname':
        u"Tutorial",
        'description': ('<div dir="ltr" lang="en">Tutorial project where '
                        'users can play with Pootle and learn more about '
                        'translation and localisation.<br />For more help on '
                        'localisation, visit the <a href="http://'
                        'translate.sourceforge.net/wiki/guide/start">'
                        'localisation guide</a>.</div>'),
        'checkstyle':
        "standard",
        'localfiletype':
        "po",
        'treestyle':
        "auto",
    }
    tutorial = Project(**criteria)
    tutorial.save()
コード例 #11
0
ファイル: project.py プロジェクト: JMassapina/pootle
def _require_project(code, name, source_language):
    """Helper to get/create a new project."""
    # XXX: should accept more params, but is enough for now
    from pootle_project.models import Project

    criteria = {
        'code': code,
        'fullname': name,
        'source_language': source_language,
        'checkstyle': 'standard',
        'localfiletype': 'po',
        'treestyle': 'auto',
    }
    new_project = Project(**criteria)
    new_project.save()

    return new_project
コード例 #12
0
def _require_project(code, name, source_language, **kwargs):
    """Helper to get/create a new project."""
    from pootle_project.models import Project

    criteria = {
        'code': code,
        'fullname': name,
        'source_language': source_language,
        'checkstyle': 'standard',
        'localfiletype': 'po',
        'treestyle': 'auto',
    }
    criteria.update(kwargs)

    new_project = Project(**criteria)
    new_project.save()

    return new_project
コード例 #13
0
ファイル: project.py プロジェクト: JeroenKnoops/pootle
def _require_project(code, name, source_language, **kwargs):
    """Helper to get/create a new project."""
    from pootle_project.models import Project

    criteria = {
        'code': code,
        'fullname': name,
        'source_language': source_language,
        'checkstyle': 'standard',
        'localfiletype': 'po',
        'treestyle': 'auto',
    }
    criteria.update(kwargs)

    new_project = Project(**criteria)
    new_project.save()

    return new_project
コード例 #14
0
ファイル: initdb.py プロジェクト: bluemutedwisdom/pootle
def create_default_projects():
    """Create the default projects that we host.

    You might want to add your projects here, although you can also add things
    through the web interface later.
    """
    from pootle_project.models import Project

    en = require_english()

    #criteria = {
    #    'code': u"pootle",
    #    'source_language': en,
    #    'fullname': u"Pootle",
    #    'description': ('<div dir="ltr" lang="en">Interface translations for '
    #                    'Pootle.<br />See the <a href="http://'
    #                    'pootle.locamotion.org">official Pootle server</a> '
    #                    'for the translations of Pootle.</div>')
    #    'checkstyle': "standard",
    #    'localfiletype': "po",
    #    'treestyle': "auto",
    #}
    #pootle = Project(**criteria)
    #pootle.save()

    criteria = {
        'code': u"tutorial",
        'source_language': en,
        'fullname': u"Tutorial",
        'description': ('<div dir="ltr" lang="en">Tutorial project where '
                        'users can play with Pootle and learn more about '
                        'translation and localisation.<br />For more help on '
                        'localisation, visit the <a href="http://'
                        'docs.translatehouse.org/projects/localization-guide/'
                        'en/latest/guide/start.html">localisation guide</a>.'
                        '</div>'),
        'checkstyle': "standard",
        'localfiletype': "po",
        'treestyle': "auto",
    }
    tutorial = Project(**criteria)
    tutorial.save()
コード例 #15
0
ファイル: initdb.py プロジェクト: lehmannro/pootle
def create_default_projects():
    """Create the default projects that we host. You might want to add your
    projects here, although you can also add things through the web interface
    later."""
    from pootle_project.models import Project

    pootle = Project(code=u"pootle")
    pootle.fullname = u"Pootle"
    pootle.description = "<div dir='ltr' lang='en'>Interface translations for Pootle. <br /> See the <a href='http://pootle.locamotion.org'>official Pootle server</a> for the translations of Pootle.</div>"
    pootle.checkstyle = "standard"
    pootle.localfiletype = "po"
    pootle.treestyle = "auto"
    pootle.save()

    tutorial = Project(code=u"tutorial")
    tutorial.fullname = u"Tutorial"
    tutorial.description = "<div dir='ltr' lang='en'>Tutorial project where users can play with Pootle and learn more about translation and localisation.<br />For more help on localisation, visit the <a href='http://translate.sourceforge.net/wiki/guide/start'>localisation guide</a>.</div>"
    tutorial.checkstyle = "standard"
    tutorial.localfiletype = "po"
    tutorial.treestyle = "auto"
    tutorial.save()
コード例 #16
0
ファイル: initdb.py プロジェクト: itsjeyd/wikitrans-pootle
def create_default_projects():
    """Create the default projects that we host. You might want to add your
    projects here, although you can also add things through the web interface
    later."""
    from pootle_project.models import Project
    from pootle_app.management import require_english

    en = require_english()

    tutorial = Project(code=u"tutorial", source_language=en)
    tutorial.fullname = u"Tutorial"
    tutorial.description = "<div dir='ltr' lang='en'>Tutorial project " \
                           "where users can play with Pootle and learn " \
                           "more about translation and localisation." \
                           "<br />For more help on localisation, visit " \
                           "the <a href='http://translate.sourceforge.net/" \
                           "wiki/guide/start'>localisation guide</a>.</div>"
    tutorial.checkstyle = "standard"
    tutorial.localfiletype = "po"
    tutorial.treestyle = "auto"
    tutorial.save()
コード例 #17
0
ファイル: views.py プロジェクト: nrtest/wikitrans-pootle
def _source_to_pootle_project(article):
    # Fetch the source_language
    sl_set = Language.objects.filter(code=article.language)

    if len(sl_set) < 1:
        return false

    source_language = sl_set[0]

    # Construct the project
    project = Project()
    project.fullname = u"%s:%s" % (article.language, article.title)
    project.code = project.fullname.replace(" ", "_").replace(":", "_")
    # PO filetype
    # project.localfiletype = "po" # filetype_choices[0]
    project.source_language = source_language

    # Save the project
    project.save()

    return project
コード例 #18
0
def create_default_projects():
    """Create the default projects that we host.

    You might want to add your projects here, although you can also add things
    through the web interface later.
    """
    from pootle_project.models import Project

    en = require_english()

    criteria = {
        'code': u"tutorial",
        'source_language': en,
        'fullname': u"Tutorial",
        'checkstyle': "standard",
        'localfiletype': "po",
        'treestyle': "auto",
    }
    tutorial = Project(**criteria)
    tutorial.save()

    criteria = {
        'active':
        True,
        'title':
        "Project instructions",
        'body': ('<div dir="ltr" lang="en">Tutorial project where users can '
                 'play with Pootle and learn more about translation and '
                 'localisation.<br />For more help on localisation, visit the '
                 '<a href="http://docs.translatehouse.org/projects/'
                 'localization-guide/en/latest/guide/start.html">localisation '
                 'guide</a>.</div>'),
        'virtual_path':
        "announcements/projects/" + tutorial.code,
    }
    ann = Announcement(**criteria)
    ann.save()
コード例 #19
0
def create_default_projects():
    """Create the default projects that we host. You might want to add your
    projects here, although you can also add things through the web interface
    later."""
    from pootle_project.models import Project
    from pootle_app.management import require_english

    en = require_english()

    #pootle = Project(code=u"pootle", source_language=en)
    #pootle.fullname = u"Pootle"
    #pootle.description = "<div dir='ltr' lang='en'>Interface translations for Pootle. <br /> See the <a href='http://pootle.locamotion.org'>official Pootle server</a> for the translations of Pootle.</div>"
    #pootle.checkstyle = "standard"
    #pootle.localfiletype = "po"
    #pootle.treestyle = "auto"
    #pootle.save()

    tutorial = Project(code=u"tutorial", source_language=en)
    tutorial.fullname = u"Tutorial"
    tutorial.description = "<div dir='ltr' lang='en'>Tutorial project where users can play with Pootle and learn more about translation and localisation.<br />For more help on localisation, visit the <a href='http://translate.sourceforge.net/wiki/guide/start'>localisation guide</a>.</div>"
    tutorial.checkstyle = "standard"
    tutorial.localfiletype = "po"
    tutorial.treestyle = "auto"
    tutorial.save()
コード例 #20
0
    def create_pootle_project(self):
        '''
        Creates a project to be used in Pootle. A templates language is created and a .pot
        template is generated from the SourceSentences in the article.
        '''
        import logging
        from django.utils.encoding import smart_str
        from pootle_app.models.signals import post_template_update

        # Fetch the source_language
        sl_set = Language.objects.filter(code=self.language.code)

        if len(sl_set) < 1:
            return false

        source_language = sl_set[0]

        # 1. Construct the project
        project = Project()
        project.fullname = u"%s:%s" % (self.language.code, self.title)
        project.code = project.fullname.replace(" ", "_").replace(":", "_")
        # PO filetype
        #project.localfiletype = "po" # filetype_choices[0]

        project.source_language = source_language
        # Save the project
        project.save()

        templates_language = Language.objects.get_by_natural_key('templates')

        # Check to see if the templates language exists. If not, add it.
        #if not project.language_exists(templates_language):
        if len(
                project.translationproject_set.filter(
                    language=templates_language)) == 0:
            project.add_language(templates_language)
            project.save()

        #code copied for wt_articles
        logging.debug("project saved")
        # 2. Export the article to .po and store in the templates "translation project". This will be used to generate translation requests for other languages.
        templatesProject = project.get_template_translationproject()
        po = self.sentences_to_po()
        poFilePath = "%s/article.pot" % (templatesProject.abs_real_path)

        oldstats = templatesProject.getquickstats()

        # Write the file
        with open(poFilePath, 'w') as f:
            f.write(smart_str(po.__str__()))

        # Force the project to scan for changes.
        templatesProject.scan_files()
        templatesProject.update(conservative=False)

        # Log the changes
        newstats = templatesProject.getquickstats()
        post_template_update.send(sender=templatesProject,
                                  oldstats=oldstats,
                                  newstats=newstats)

        # Add a reference to the project in the SourceArticle
        self.pootle_project = project
        self.save()

        return project
コード例 #21
0
ファイル: models.py プロジェクト: NickRuiz/wikitrans-pootle
 def create_pootle_project(self):
     '''
     Creates a project to be used in Pootle. A templates language is created and a .pot
     template is generated from the SourceSentences in the article.
     ''' 
     import logging
     from django.utils.encoding import smart_str
     from pootle_app.models.signals import post_template_update
 
 
     # Fetch the source_language
     sl_set = Language.objects.filter(code = self.language.code)
     
     if len(sl_set) < 1:
         return False
 
     source_language = sl_set[0]
         
     # 1. Construct the project
     project = Project()
     project.fullname = u"%s:%s" % (self.language.code, self.title)
     project.code = project.fullname.replace(" ", "_").replace(":", "_")
     # PO filetype
     #project.localfiletype = "po" # filetype_choices[0]
     
     project.source_language = source_language
   # Save the project
     project.save()
     
     templates_language = Language.objects.get_by_natural_key('templates')
     
     # Check to see if the templates language exists. If not, add it.
     #if not project.language_exists(templates_language):
     if len(project.translationproject_set.filter(language=templates_language)) == 0:
         project.add_language(templates_language)
         project.save()
     
     #code copied for wt_articles
     logging.debug ( "project saved")
     # 2. Export the article to .po and store in the templates "translation project". This will be used to generate translation requests for other languages.
     templatesProject = project.get_template_translationproject()
     po = self.sentences_to_po()
     poFilePath = "%s/article.pot" % (templatesProject.abs_real_path)
     
     oldstats = templatesProject.getquickstats()
     
     # Write the file
     with open(poFilePath, 'w') as f:
         f.write(smart_str(po.__str__()))
     
     # Force the project to scan for changes.
     templatesProject.scan_files()
     templatesProject.update(conservative=False)
     
     # Log the changes
     newstats = templatesProject.getquickstats()
     post_template_update.send(sender=templatesProject, oldstats=oldstats, newstats=newstats)
     
     # Add a reference to the project in the SourceArticle
     self.pootle_project = project
     self.save()
         
     return project