seboettg / citeproc-php

Full-featured CSL 1.0.1 processor for PHP
MIT License
73 stars 38 forks source link

Given author name in MLA style is abbreviated #114

Closed felixhelix closed 1 year ago

felixhelix commented 2 years ago

Please follow the general troubleshooting steps first:

Bug reports:

If initialize="false" and initialize-with=". " is given, the latter is only applied if Initials are already given:

From the specs:

initialize When set to “false” (the default is “true”), given names are no longer initialized when “initialize-with” is set. However, the value of “initialize-with” is still added after initials present in the full name (e.g. with initialize set to “false”, and initialize-with set to “.”, “James T Kirk” becomes “James T. Kirk”).

Unfortunately citeproc-php seems to initialize a name even if initialize="false" but initialize-with=". " is given.

Used CSL stylesheet:

modern-language-association.csl

The respective section is:

 <macro name="author">
    <names variable="author">
      <name name-as-sort-order="first" and="text" delimiter-precedes-last="always" delimiter-precedes-et-al="always" initialize="false" initialize-with=". "/>
      <label form="long" prefix=", "/>
      <substitute>
        <names variable="editor"/>
        <names variable="translator"/>
        <text macro="title"/>
      </substitute>
    </names>
  </macro>

Used CSL metadata

Please replace these lines with your used metadata, for instance:

    [
        {
            "author": [
                {
                    "family": "Helix", 
                    "given": "Felix"
                }, 
            ], 
            "id": "ITEM-2", 
            "type": "article-journal",
            "title": "How to do anything at all",
            "container-title":  "motivational studies",
            "publisher-place":  "Cologne, Germany",
            "container-title-short": "most",
            "volume": "1";
            "issue": "1"
        }
    ]

Yours Felix

felixhelix commented 2 years ago

@seboettg Can you have a look at this? Thanks, Felix

felixhelix commented 2 years ago

@seboettg I digged into this and I think the problem is with the boolval() function in InheritableNameAttributesTrait,php:

$this->initialize = boolval((string) $attribute);

boolval returns "true" for any string but an empty one. So even if the attribute value is "false", it returns true. Accordingly, the name gets abbrevitated if initializeWith is not empty:

$useInitials = $this->initialize && !is_null($this->initializeWith) && $this->initializeWith !== false; (Name.php)

A solution could be to assign the value as this:

$this->initialize = ((string) $attribute) == 'true' ? true : false;

This should then be applied to 'et-al-use-last' as well, as here also boolval() is used.

What do you think?

Your's

Felix

seboettg commented 2 years ago

Hey @felixhelix! Thank you for debugging this issue. I'm gonna build a fix soon.

seboettg commented 2 years ago

@felixhelix Should be solved with version 2.5.0.

seboettg commented 2 years ago

@felixhelix Can you confirm that the issue is fixed by closing this ticket?

felixhelix commented 1 year ago

@seboettg

I cloned the updated repo to test it in my local OJS installation. I also needed to update the Collection repo because I got the error "undefined method Seboettg\Collection\ArrayList::collectToString()".

Now I get the error

[::1]:64910 [500]: GET /index.php/ojstest/article/view/7 - Uncaught Error: Call to undefined method Seboettg\Collection\ArrayList::hasKey() in C:\Users\steph\Documents\UB\development\ojs-3.3.0-8\plugins\generic\citationStyleLanguage\lib\vendor\seboettg\citeproc-php\src\Locale\LocaleXmlParserTrait.php:132

can you help me with that?

Yours,

Felix

seboettg commented 1 year ago

Hi @felixhelix I assume citeproc try to use a wrong version of seboettg/collection. Please run the following command in the project root directory where citeproc-php is used:

composer show seboettg/collection

You should find a version hint that look like that:

versions : * v3.1.0