Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

intl / l10n / number formatting #21

Open
rotdrop opened this issue Sep 27, 2021 · 4 comments
Open

intl / l10n / number formatting #21

rotdrop opened this issue Sep 27, 2021 · 4 comments

Comments

@rotdrop
Copy link

rotdrop commented Sep 27, 2021

Is there any support for number locales different from EN/US? I know I can tell OpenTBS with e.g. ope=tbs:percent (or curr, etc.) that field is numeric. However, the number itself does not seem to be converted to the documents language.

Maybe related: if I format a cell in the template as percentage, the value will be displayed as zero after merging. In the XML I find something like this:

<table:table-cell table:style-name="Tabelle3.F3" office:value-type="percentage" office:value="0">
  <text:p text:style-name="P11">
    0.0068
  </text:p>
</table:table-cell>

So it seems that LibreOffice remembers the invalid number from the template, resulting from the TBS template field in square brackets. Also, if using e.g. German then we have a comma as decimal separator and a point to separate thousands, e.g. US 1,000.56 is 1.000,56 in German and a couple of other languages.

Is there any experience with OpenTBS in the context of non-US English?

Kind thanks for any hints!

@Skrol29
Copy link
Owner

Skrol29 commented Sep 27, 2021

Hi,
What is your template contents ? I mean with TBS fields. And what are you merging it with ?

@rotdrop
Copy link
Author

rotdrop commented Sep 28, 2021

Ok, this is the template with automatic sub-blocks and one column with ope=tbs:percent, but without adding the percent-formatting in the document:

template-sub-tables.odt

An example data-set would be (stripped down to one row, the sub-block stuff is working):

$data = [
  'placeholder' => 'This has been substituted',
  'outer' => [
    'col1' => 'Outer Row 1, Column 1 Data',
    'inner' => [
       'col1' => 0.005,
       'col2' => 'Inner Row 1, Column 2 Data',
    ],
  ], 
];

The data is also available in a simple OpenTBS command line app under https://github.com/rotdrop/opentbs-tool in the examples/ subdir.

The data is merged by replacing the data-source array of TBS with the given data and doing a block merge with the key 'outer' like $tbs->MergeBlock('outer', $data['outer']);

It works so far, the "percentage" numbers are then output as numbers in US or "C" notation with a dot as decimal divider-char. The output with a slightly more complicated data-set with more than on row is as follows:

template-sub-tables-opentbs-6dc0b337567915e0f670152d55bbe71c.odt

Here the document language is in principle German. The number is displayed without percent and with a decimal dot. Looking at the numer-format of the substituted document shows the table cell as "text" with "@" format character.

If I now start to format table cells as percent in LibreOffice things start to become complicated:

  • after saving the OpenTBS tags are hidden, but not gone.
  • if I format the table cell back to text, then the orignal text with the TBS-tags are not restored, but replaced by "0 %"
    So this does not work. Of course, the two points above are a LO "feature", this just means it can't be done this way, where "it" means: "display a number as percentage with the number format of the document locale".

Internationalization would really be nice as office-documents tend to be exchanged between non-nerds.

BTW: what would be the expected result? Should ope=tbe:percent ouput a percentage sign behind the number? And should the field type in the substituted document be adjusted to a numerical type?

I suppose I will now go and read a little bit more of the documentation; perhaps there is already something built-in to achieve what I want here.

@rotdrop
Copy link
Author

rotdrop commented Sep 28, 2021

Ok, so adding frm='0,000 %' seems to work. Then may I ask what actually "ope=tbs:percent" is doing? I get the desired result without it, by only specifying the format, and ope=tbs:percent alone does not hack it.

It would be nice if the default number formatting could somehow be styled according to the document language, instead of using the C locale by default.

Thank you for your work! I think using the format-options I get what I want to some extend.

@rotdrop
Copy link
Author

rotdrop commented Sep 28, 2021

frm='0,000. €' will give the expected output, e.g. 1234 is output as "1,234 €" without decimals, however, trying to exchange the role of dot and comma does not work, using the number format frm='0.000, €' with the same number results in "1234.000, €" instead of the expected "1.234 €". Surprisingly the format frm='0.000. €' with a trailing dot works.

The format frm='0,00 %' seems to work, i.e. "0.0068" is output as "0,68 %" (but regardless of ope=tbe:percent, but perhaps that is a feature).

Is this comma vs. dot feature somewhere documented? Is it even supported, or do I get the correct result by chance?

Kind thanks Claus

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants