Thursday, December 19, 2013

first parsing steps : request for comments

" To help disambiguation when a line type can not be identified without
" context information, we define 3 domains and a function which returns
" a list with first/last lines of each domain.

let s:po_dom_1 = {
\ 'name' : "preamble_comment_domain"
\, 'first': { 'number': 0 }
\, 'last' : { 'pattern': '\n\_^\s*msgid\s\+""\s*\(\n\s*\)*\_^*\s*msgstr\s\+""\s*$' }
\, 'comment': "Optionnal, might be from 0 to 0"
\}

let s:po_dom_2 = {
\ 'name' : "header_domain"
\, 'first' : { 'deferred': "s:po_dom_1.get_line('last') + 1" }
\, 'last' : { 'pattern': '\n\_^\s*\(#\|msgid\s\+".*"\).*$' }
\}

let s:po_dom_3 = {
\ 'name' : "messages_domain"
\, 'first' : { 'deferred': "s:po_dom_2.get_line('last') + 1" }
\, 'last' : { 'pattern': '\%$' }
\}

let s:po_dom_funcs = { }

function! s:po_dom_funcs.get_line(key)
if a:key !~# '^\(first\|last\)$'
return 0
endif

let ldict = eval('self.' . a:key)
if has_key(ldict, 'number')
return ldict.number
elseif has_key(ldict, 'deferred')
return eval(ldict.deferred)
endif

let search_flags = 'cW'
if a:key == 'last'
let search_from = self.get_line('first')
else
let search_from = self.get_line('last')
let search_flags .= 'b'
endif

if search_from == 0
let search_from = 1
endif

let save_cursor = getpos('.')
call cursor(search_from, 1)
let fret = search(ldict.pattern, search_flags)
call cursor(save_cursor[1], save_cursor[2])
return fret
endfunction

let s:sorted_domains = [ s:po_dom_1, s:po_dom_2, s:po_dom_3 ]

for dom in s:sorted_domains
let dom.get_line = s:po_dom_funcs.get_line
endfor

function! Get_po_doms()
let fret = []
for dom in s:sorted_domains
let fret += [ {
\ 'name' : dom.name
\, 'first_line': dom.get_line('first')
\, 'last_line' : dom.get_line('last')
\} ]
endfor
return fret
endfunction
# Translation of debian-reference to French
# Copyright (C) 2009-2012 Debian French l10n team <debian-l10n-french@lists.debian.org>.
# This file is distributed under the same license as the debian-reference package.
#
# Jean-Luc Coulon (f5ibh) <jean-luc.coulon@wanadoo.fr>, 2009, 2010.
# David Prévot <david@tilapin.org>, 2010-2012.


#
msgid ""
msgstr ""
"Project-Id-Version: debian-reference\n"
"POT-Creation-Date: 2013-11-09 22:36+0900\n"
"PO-Revision-Date: 2013-12-19 13:13+0100\n"
"Last-Translator: Julien Patriarca <leatherface@debian.org>\n"
"Language-Team: French <debian-l10n-french@lists.debian.org>\n"
"Language: fr\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 1.5.4\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"

# Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia
# pellentesque sapien, sed lacinia urna. Quisque faucibus, sem nec tempus
# vulputate, sem erat condimentum lorem, id dignissim nisl mi a arcu. Donec
#. type: Content of: <book><appendix><section><para>
#: labasouici.c
#, fuzzy
#| msgctxt ""
#| msgid "avant c'etait comme ca et puis comme ça"
msgid ""
"The source of the English original document is currently written in <ulink "
"url=\"&asciidoc;\">AsciiDoc</ulink> text files. <ulink url=\"&asciidoc;"
"\">AsciiDoc</ulink> is used as convenience only since it is less typing than "
"straight XML and supports table in the very intuitive format. You should "
"think XML doccument and PO files as real source files. Via build script, it "
"is converted to DocBook XML format and automatically generated data are "
"inserted to form a final Docbook XML source. This final Docbook XML source "
"can be converted to HTML, plain text, PostScript, and PDF. Currently, only "
"HTML and plain text conversions are enabled."
msgstr ""
"La source du document original en anglais est actuellement écrite sous forme "
"de fichiers texte <ulink url=\"&asciidoc;\">AsciiDoc</ulink>. <ulink url="
"\"&asciidoc;\">AsciiDoc</ulink> n'est utilisé que par facilité car il "
"demande moins de frappe que l'XML natif et prend en charge les tableaux dans "
"un format très intuitif. Vous devez avoir à l'esprit que les fichiers XML et "
"PO sont les vrais fichiers sources. Ils sont convertis dans le format XML "
"DocBook par le script de construction et les données créées automatiquement "
"sont insérées afin de former un source final XML Docbook. Ce source final "
"XML Docbook peut être converti en HTML, en text brut, en PostScript et en "
"PDF. Actuellement, seules les conversions HTML et texte brut sont réalisées."

# tagoule
msgid "http://en.wikipedia.org/wiki/Accelerated_Graphics_Port"
msgstr "http://fr.wikipedia.org/wiki/Accelerated_Graphics_Port"
Hello,

Still working my way to yellow belt in the Vim Scripting Art, I come
to you with a little piece of code I wrote to later serve in a plugin
I'm trying to write (to work with GNU Gettext PO files). I would be
interrested in comments from >= yellow belt Vim Scripters to improve my
code and my skills. And I have to say, i find my 'get_line' function
ugly. ^^

I think (hope) the attached code is rather self-explanatory, and
there's also a small sample 'po' file on which this code is supposed to
work. This will be the plugin first step at parsing a PO file.

Regards,

--
 ___________________
| $ post_tenebras ↲ |       waouh !
| GNU        \ /    |      /
|          -- * --  |     o
| $ who ↲    / \    |_-- ~_|
| Alexandre Hoïde   |  _/| |
 -------------------

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment