2

I have a dictionary in my python code which contains language codes and names: {'eng': English,'ger': German,....}. I have created variable in my sphinx conf.py file equivalent to this dictionary and I want to use that variable and show it in my sphinx documentation with table which has 2 columns: code, name. I am using csv-table to show data.

I have tried to join keys and values in one string and show without tables but there was a problem with new lines.

Some code below:

In constants.py

 LANGS = {
    'eng': 'en',
    'ger': 'de',
    'fra': 'fr',
    'spa': 'es',
    'ita': 'it',
    'por': 'pt',
    'gre': 'el',
....
}

In conf.py

 for k, v in LANGS.iteritems():
    ll = pycountry.languages.get(alpha_2=v)
    if ll is not None:
        languages[k] = ll.name

rst_epilog = """.. |languages| replace:: {languages} """.format(languages=languages)
bad_coder
  • 11,289
  • 20
  • 44
  • 72
  • Suggest using a csvtable instead. Docs: https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#table-directives Syntax: http://docutils.sourceforge.net/docs/ref/rst/directives.html#csv-table – Steve Piercy May 13 '19 at 17:32
  • Please show us what the problem is. Don't just say "there was a problem with new lines". What does your csv-table look like? – mzjn May 14 '19 at 09:42
  • I have created string like this: `langs = ' '.join("{!s} - {!s}, \n".format(key, val) for (key, val) in languages.items())` in .rst file I have something like this: `Available languages are: |langs|` In exported pdf file langs printed like this: Available languages are: eng - English, ger - German, fra - French, spa - Spanish, ita - Italian, por - Portuguese,.... just side by side, without new lines. – – Shushan Hovhannisyan May 15 '19 at 13:04

0 Answers0