Skip to content

Punctuation Terms Missing: Leads to missing or misplaced spaces between labels and suffixes #199

@urshofer

Description

@urshofer

Hello –

Thanks for your lib. It's cool.

I found something that caused quite a lot of display errors in my case. It took me a while to get to the bottom of it.

(Most? All?) locale files define punctuations like this:

    <term name="open-quote">“</term>
    <term name="close-quote">”</term>
    <term name="open-inner-quote">‘</term>
    <term name="close-inner-quote">’</term>
    <term name="page-range-delimiter">–</term>

The Class Punctuation is defined like:

class Punctuation extends Enum
{
    public const OPEN_QUOTE = "open-quote";
    public const CLOSE_QUOTE = "close-quote";
    public const OPEN_INNER_QUOTE = "open-inner-quote";
    public const CLOSE_INNER_QUOTE = "close-inner-quote";
    public const PAGE_RANGE_DELIMITER = "page-range-delimiter";
    public const COLON = "colon";
    public const COMMA = "comma";
    public const SEMICOLON = "semicolon";

   ...

}

Obviously, there's a difference: Comma, Semicolon and Colon are missing.

This leads to render errors, for example here:

    private function appendLabel($data, $var, $name): string
    {
        $this->label->setVariable($var);
        $renderedLabel = trim($this->label->render($data));
        if (empty($renderedLabel)) {
            return $name;
        }
        if ($this->renderLabelBeforeName) {
            $delimiter = !in_array(
                trim($this->label->renderSuffix()),
                Punctuation::getAllPunctuations()
            ) ? " " : "";
            $result = $renderedLabel . $delimiter . trim($name);
        } else {
            $delimiter = !in_array(
                trim($this->label->renderPrefix()),
                Punctuation::getAllPunctuations()
            ) ? " " : "";
            $result = trim($name) . $delimiter . $renderedLabel;
        }
        return $result;
    }

Because Punctuation::getAllPunctuations() returns emtpy values for commas, semicolons and colons. A suffix like " " is trimmed to "" and equals therefore to Comma, Semicolon or Colon, which is obviously wrong.

Without changing the code, a simple workaround is to add the following terms to the csl file:

      <term name="comma">,</term>
      <term name="colon">:</term>
      <term name="semicolon">;</term>

Otherwise, setting a default for these 3 values might be better. Would be true for most of the locales.

❤️

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions