1. Eric Larson
  2. Dragoman

Commits

Eric Larson  committed 05767cf

Can create a language with the client now

  • Participants
  • Parent commits 36c2404
  • Branches default

Comments (0)

Files changed (1)

File dragoman/lib/client.py

View file
         self.catalog = catalog
         self.lang = lang
         self.service = service
-        print 'bulk_by_po' in open(__file__, 'r').read()
+        self.name = None
 
     def _url(self, phrase=None):
         params = {
         return phrase
     __call__ = get
 
+    def exists(self):
+        resp, content = self.service.request('languages', {})
+        langs = simplejson.loads(content)
+        return self.lang in langs
+
+    def create(self, name):
+        reqparams = {'method': 'POST'}
+        self.name = name
+        doc = {
+            'abbrev': self.lang,
+            'name': self.name
+        }
+        reqparams = {
+            'headers': {
+                'Content-Type': 'application/json',
+            },
+            'method': 'POST',
+            'body': simplejson.dumps(doc),
+        }
+        resp, content = self.service.request('languages', {},  **reqparams)
+        if resp.status == 201 and content:
+            return content
+        raise RequestFailure('Creating language (%s, %s) failed' % (self.lang, self.name), resp, content)
 
     def add(self, phrase, translation, **extra):
         ctx = extra or {}
             return True
         raise RequestFailure('add method failed', resp, content)
 
-
     def bulk(self, phrases):
         doc = simplejson.dumps({ self.lang : phrases })
         urlparams =  {'catalog': self.catalog, 'language': self.lang,}
             return True
         raise RequestFailure('bulk add failed', resp, content)
 
-	def bulk_by_po(self, po_file):
-		extra_keys = [
+    def bulk_by_po(self, po_file):
+        extra_keys = [
             'extracted_comment', 'reference', 'flag',
             'previous_untranslated_string',
         ]
-        po = GettextCatalog(pofile, lang)
+        po = GettextCatalog(po_file, self.lang)
         phrases = []
         for m in po.messages:
             extra = [getattr(po, k) for k in extra_keys if hasattr(po, k)]
             doc.update(extra)
             phrases.append(doc)
         return self.bulk(phrases)
-		
+        
 
 
 class Catalog(object):