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

Getting yaml values in single quotes #304

Closed
boydkelly opened this issue Apr 22, 2021 · 8 comments
Closed

Getting yaml values in single quotes #304

boydkelly opened this issue Apr 22, 2021 · 8 comments

Comments

@boydkelly
Copy link

Recently came back to my website and it seems that po4a is single qoteing some yaml header values.

In an en pot file I have:

7 #. type: Plain text
  6 #: content/en/resources/ankataa.com.adoc:20
  5 msgid "tags: [ \"jula\", \"language\" ]"
  4 msgstr ""

in the French translated po file:

19 #. type: Plain text
 20 #: content/en/resources/ankataa.com.adoc:20
 21 msgid "tags: [ \"jula\", \"language\" ]"
 22 msgstr "[ \"jula\", \"langue\"]"

But in the final French document after running po4a I have (single quoted):

tags: '[ "jula", "langue"]'

I can get by with some sed for the time being. Here are the options I am using to run po4a.

[options] -M UTF-8 -L UTF-8  --package-name "Blog" --package-version "1.0" --master-language "en" -o "entry='tags categories lang'"-                                                                                                                               

[po4a_langs] fr
[po4a_paths] l10n/pot/en/$master.pot $lang:l10n/po/$lang/$master.po
[type: asciidoc] content/en/post/smoketest.adoc $lang:content/$lang/post/smoketest.adoc opt:"-o tablecells"
[type: asciidoc] content/en/resources/ankataa.com.adoc $lang:content/$lang/resources/ankataa.com.adoc   

po4a --version
po4a version 0.63.

Thanks for all your work on this amazing project!

@boydkelly
Copy link
Author

This is probably realated. but also when there is seemingly no value for an item...
in my header I have

 ---
  menu:
    jula:
  title: 'Jula Study Resources'                                                                                                                
  ---

if I just request the translation of jula to be the same, then po4a will make the line

jula: ' '

which the hugo web server is not happy with... :)

@jnavila
Copy link
Collaborator

jnavila commented Apr 22, 2021

Is it a regression? If so, can you bisect it?

@mquinson
Copy link
Owner

mquinson commented Nov 7, 2021

Hello @boydkelly, sorry for the delay.

Can you provide us with a way to reproduce the bug? Maybe an access to your code, or a minimal example that we could play with? We cannot debug po4a without something like this.

Thanks for reporting,

@boydkelly
Copy link
Author

boydkelly commented Dec 7, 2021

Hi Sorry, I had put this on back burner and since I worked around the issue with a bit of sed....

Please see the attached example files. The source en/font-test.adoc yaml header has an entry: tags: [ "tech", "web", "fonts" ]
(And as far as I know this is valid; I like to keep it on one line so I can grep it if needed)
But po4a translates it to: tags: '[ "tech", "web", "polices" ]' (with single quotes)

The hugo static site generator will complain about that and the build will fail. Now of course this could be a hugo problem as well. I'm not sure what is considered valid here. And I do just fix this in a script with sed so there is no urgency on my part.

Thanks for such a great tool!!!

yaml-test.tar.gz

@dbaio
Copy link
Contributor

dbaio commented Jan 24, 2022

How to reproduce:

example.yaml
example.po
-->
example_pt-br.yaml
example_pt-br.po

$ po4a-gettextize \
	--format yaml \
	--option keys="title description" \
	--master "example.yaml" \
        --master-charset "UTF-8" \
        --po "example.po"
$ po4a-translate \
	--format yaml \
	--option keys="title description" \
	--master "example.yaml" \
        --master-charset "UTF-8" \
        --po "example_pt-br.po" \
        --localized "example_pt-br.yaml" \
        --localized-charset "UTF-8"

It's the same when using Asciidoc formatter.

@dbaio
Copy link
Contributor

dbaio commented Jan 24, 2022

If you see the tests, there are translations with quotes where the original doesn't.

skiparray.yaml
skiparray.trans

It's different, but it's not an issue.


The issue here is when this happens:
tags: ["jula", "language"].
-->
tags: '["jula", "language"]'.


These different behaviors are odd.

$ cat single_line.yml
tags: ["bsdl", "gpl", "FreeBSD License"]
$ yamlpp-load-dump -M YAML::Tiny < single_line.yml
---
tags: '["bsdl", "gpl", "FreeBSD License"]'
$ yamlpp-load-dump -M YAML::PP < single_line.yml
---
tags: ["bsdl", "gpl", "FreeBSD License"]

@dbaio
Copy link
Contributor

dbaio commented Jan 24, 2022

It seems there is already a workaround for YAML::Tiny here.

One more would be something like this:

	if ( Scalar::Util::looks_like_number($el) ) {
		$self->pushline("$header $el\n");
	} elsif ( $el =~ /^\[.*\]$/ ) {
		$self->pushline("$header $el\n");
	} else {
		$self->pushline( $header . ' ' . YAML::Tiny::_dump_scalar( "dummy", $el ) . "\n" );
	}

But I'm not sure if you want to look into the yaml modules for a better solution. Sorry, I don't have much experience with this.

@boydkelly
Copy link
Author

boydkelly commented Jul 22, 2022

Thank you very much!!! Yes this is now working for me. I was anxious to ditch my sed script running after po41 and so packaged this rpm till Fedora gets it update to 0.67. Covers a number of rpm distros...

https://copr.fedorainfracloud.org/coprs/boydkelly/po4a/

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

No branches or pull requests

4 participants