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

Feature/aut 3965/enable vertical writing #4168

Merged
merged 6 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions locales/ja-HS/lang.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
<tao:LanguageUsages rdf:resource="http://www.tao.lu/Ontologies/TAO.rdf#LanguageUsageGUI"/>
<tao:LanguageUsages rdf:resource="http://www.tao.lu/Ontologies/TAO.rdf#LanguageUsageData"/>
<tao:LanguageOrientation rdf:resource="http://www.tao.lu/Ontologies/TAO.rdf#OrientationLeftToRight"/>
<tao:LanguageVerticalWritingMode rdf:resource="http://www.tao.lu/Ontologies/TAO.rdf#WritingModeVerticalRl"/>
</rdf:Description>
</rdf:RDF>
1 change: 1 addition & 0 deletions locales/ja-JP/lang.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
<tao:LanguageUsages rdf:resource="http://www.tao.lu/Ontologies/TAO.rdf#LanguageUsageGUI"/>
<tao:LanguageUsages rdf:resource="http://www.tao.lu/Ontologies/TAO.rdf#LanguageUsageData"/>
<tao:LanguageOrientation rdf:resource="http://www.tao.lu/Ontologies/TAO.rdf#OrientationLeftToRight"/>
<tao:LanguageVerticalWritingMode rdf:resource="http://www.tao.lu/Ontologies/TAO.rdf#WritingModeVerticalRl"/>
</rdf:Description>
</rdf:RDF>
1 change: 1 addition & 0 deletions locales/ja-LE/lang.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
<tao:LanguageUsages rdf:resource="http://www.tao.lu/Ontologies/TAO.rdf#LanguageUsageGUI"/>
<tao:LanguageUsages rdf:resource="http://www.tao.lu/Ontologies/TAO.rdf#LanguageUsageData"/>
<tao:LanguageOrientation rdf:resource="http://www.tao.lu/Ontologies/TAO.rdf#OrientationLeftToRight"/>
<tao:LanguageVerticalWritingMode rdf:resource="http://www.tao.lu/Ontologies/TAO.rdf#WritingModeVerticalRl"/>
</rdf:Description>
</rdf:RDF>
1 change: 1 addition & 0 deletions locales/ja-UE/lang.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
<tao:LanguageUsages rdf:resource="http://www.tao.lu/Ontologies/TAO.rdf#LanguageUsageGUI"/>
<tao:LanguageUsages rdf:resource="http://www.tao.lu/Ontologies/TAO.rdf#LanguageUsageData"/>
<tao:LanguageOrientation rdf:resource="http://www.tao.lu/Ontologies/TAO.rdf#OrientationLeftToRight"/>
<tao:LanguageVerticalWritingMode rdf:resource="http://www.tao.lu/Ontologies/TAO.rdf#WritingModeVerticalRl"/>
</rdf:Description>
</rdf:RDF>
26 changes: 22 additions & 4 deletions models/classes/Language/Language.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,21 @@ class Language implements JsonSerializable
/** @var string */
private $orientation;

public function __construct(string $uri, string $code, string $label, string $orientation)
{
/** @var ?string */
private $verticalWritingMode;

public function __construct(
string $uri,
string $code,
string $label,
string $orientation,
?string $verticalWritingMode = null
) {
$this->uri = $uri;
$this->code = $code;
$this->orientation = $orientation;
$this->label = $label;
$this->verticalWritingMode = $verticalWritingMode;
}

public function getUri(): string
Expand All @@ -68,13 +77,22 @@ public function getOrientation(): string
return $this->orientation;
}

public function getVerticalWritingMode(): ?string
{
return $this->verticalWritingMode;
}

public function jsonSerialize(): array
{
return [
$properties = [
'uri' => $this->uri,
'code' => $this->code,
'label' => $this->label,
'orientation' => $this->orientation,
'orientation' => $this->orientation
];
if ($this->verticalWritingMode) {
$properties['verticalWritingMode'] = $this->verticalWritingMode;
}
return $properties;
}
}
15 changes: 13 additions & 2 deletions models/classes/Language/Repository/LanguageRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,29 @@ public function findAvailableLanguagesByUsage(): LanguageCollection
$values = $language->getPropertiesValues(
[
OntologyRdf::RDF_VALUE,
tao_models_classes_LanguageService::PROPERTY_LANGUAGE_ORIENTATION
tao_models_classes_LanguageService::PROPERTY_LANGUAGE_ORIENTATION,
tao_models_classes_LanguageService::PROPERTY_LANGUAGE_VERTICAL_WRITING_MODE
]
);

$orientationUri = $values[tao_models_classes_LanguageService::PROPERTY_LANGUAGE_ORIENTATION][0]->getUri();

$verticalMode = null;
$verticalPropVal = $values[tao_models_classes_LanguageService::PROPERTY_LANGUAGE_VERTICAL_WRITING_MODE];
if ($verticalPropVal) {
$verticalUri = $verticalPropVal[0]->getUri();
$verticalMode = $verticalUri === tao_models_classes_LanguageService::INSTANCE_VERTICAL_WRITING_MODE_RL
? 'vertical-rl'
: 'vertical-lr';
}

$output->add(
new Language(
$language->getUri(),
$values[OntologyRdf::RDF_VALUE][0]->__toString(),
$language->getLabel(),
$orientationUri === tao_models_classes_LanguageService::INSTANCE_ORIENTATION_RTL ? 'rtl' : 'ltr'
$orientationUri === tao_models_classes_LanguageService::INSTANCE_ORIENTATION_RTL ? 'rtl' : 'ltr',
$verticalMode
)
);
}
Expand Down
4 changes: 4 additions & 0 deletions models/classes/class.LanguageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,14 @@ class tao_models_classes_LanguageService extends tao_models_classes_GenerisServi
public const CLASS_URI_LANGUAGES_USAGES = 'http://www.tao.lu/Ontologies/TAO.rdf#LanguagesUsages';
public const PROPERTY_LANGUAGE_USAGES = 'http://www.tao.lu/Ontologies/TAO.rdf#LanguageUsages';
public const PROPERTY_LANGUAGE_ORIENTATION = 'http://www.tao.lu/Ontologies/TAO.rdf#LanguageOrientation';
public const PROPERTY_LANGUAGE_VERTICAL_WRITING_MODE =
'http://www.tao.lu/Ontologies/TAO.rdf#LanguageVerticalWritingMode';
wazelin marked this conversation as resolved.
Show resolved Hide resolved
public const INSTANCE_LANGUAGE_USAGE_GUI = 'http://www.tao.lu/Ontologies/TAO.rdf#LanguageUsageGUI';
public const INSTANCE_LANGUAGE_USAGE_DATA = 'http://www.tao.lu/Ontologies/TAO.rdf#LanguageUsageData';
public const INSTANCE_ORIENTATION_LTR = 'http://www.tao.lu/Ontologies/TAO.rdf#OrientationLeftToRight';
public const INSTANCE_ORIENTATION_RTL = 'http://www.tao.lu/Ontologies/TAO.rdf#OrientationRightToLeft';
public const INSTANCE_VERTICAL_WRITING_MODE_RL = 'http://www.tao.lu/Ontologies/TAO.rdf#WritingModeVerticalRl';
public const INSTANCE_VERTICAL_WRITING_MODE_LR = 'http://www.tao.lu/Ontologies/TAO.rdf#WritingModeVerticalLr';
// --- OPERATIONS ---

/**
Expand Down
24 changes: 24 additions & 0 deletions models/ontology/tao.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,30 @@
<rdfs:comment xml:lang="en-US"><![CDATA[Right-to-left language orientation]]></rdfs:comment>
</rdf:Description>

<rdf:Description rdf:about="http://www.tao.lu/Ontologies/TAO.rdf#LanguageVerticalWritingModes">
<rdfs:subClassOf rdf:resource="http://www.tao.lu/Ontologies/TAO.rdf#SystemObject"/>
<rdfs:label xml:lang="en-US"><![CDATA[Vertical writing mode enum]]></rdfs:label>
<rdfs:comment xml:lang="en-US"><![CDATA[Vertical writing mode enum, for languages which support vertical writing]]></rdfs:comment>
</rdf:Description>
<rdf:Description rdf:about="http://www.tao.lu/Ontologies/TAO.rdf#LanguageVerticalWritingMode">
<rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#Property"/>
<rdfs:domain rdf:resource="http://www.tao.lu/Ontologies/TAO.rdf#Languages"/>
<rdfs:range rdf:resource="http://www.tao.lu/Ontologies/TAO.rdf#LanguageVerticalWritingModes"/>
<rdfs:label xml:lang="en-US"><![CDATA[Vertical writing mode property]]></rdfs:label>
<rdfs:comment xml:lang="en-US"><![CDATA[Vertical writing mode property of a language]]></rdfs:comment>
<generis:Multiple rdf:resource="http://www.tao.lu/Ontologies/generis.rdf#True" />
</rdf:Description>
<rdf:Description rdf:about="http://www.tao.lu/Ontologies/TAO.rdf#WritingModeVerticalRl">
<rdf:type rdf:resource="http://www.tao.lu/Ontologies/TAO.rdf#LanguageVerticalWritingModes"/>
<rdfs:label xml:lang="en-US"><![CDATA[Vertical-right-to-left writing mode]]></rdfs:label>
<rdfs:comment xml:lang="en-US"><![CDATA[Vertical-right-to-left language writing mode]]></rdfs:comment>
</rdf:Description>
<rdf:Description rdf:about="http://www.tao.lu/Ontologies/TAO.rdf#WritingModeVerticalLr">
<rdf:type rdf:resource="http://www.tao.lu/Ontologies/TAO.rdf#LanguageVerticalWritingModes"/>
<rdfs:label xml:lang="en-US"><![CDATA[Vertical-left-to-right writing mode]]></rdfs:label>
<rdfs:comment xml:lang="en-US"><![CDATA[Vertical-left-to-right language writing mode]]></rdfs:comment>
</rdf:Description>

<!-- Users -->
<rdf:Description rdf:about="http://www.tao.lu/Ontologies/TAO.rdf#User">
<rdfs:subClassOf rdf:resource="http://www.tao.lu/Ontologies/generis.rdf#User"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,15 @@ private function getLanguageCollection(): LanguageCollection
'uri',
'en-US',
'label',
'ltr'
'ltr',
null
),
new Language(
'uri',
'pt-BR',
'label',
'ltr'
'ltr',
null
),
]);
}
Expand Down
3 changes: 2 additions & 1 deletion test/unit/models/classes/Language/LanguageCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public function setUp(): void
'uri',
'pt-BR',
'Portuguese',
tao_models_classes_LanguageService::INSTANCE_ORIENTATION_LTR
tao_models_classes_LanguageService::INSTANCE_ORIENTATION_LTR,
null
);
}

Expand Down
34 changes: 31 additions & 3 deletions test/unit/models/classes/Language/LanguageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,23 @@ public function testGetters(): void
'uri',
'pt-BR',
'Portuguese',
tao_models_classes_LanguageService::INSTANCE_ORIENTATION_LTR
tao_models_classes_LanguageService::INSTANCE_ORIENTATION_LTR,
null
);

$this->assertSame('uri', $language->getUri());
$this->assertSame('pt-BR', $language->getCode());
$this->assertSame('Portuguese', $language->getLabel());
$this->assertSame(tao_models_classes_LanguageService::INSTANCE_ORIENTATION_LTR, $language->getOrientation());
$this->assertSame(null, $language->getVerticalWritingMode());

$language = new Language(
'uri',
'ja-JP',
'Japanese',
'ltr',
'vertical-rl'
);
$this->assertSame('vertical-rl', $language->getVerticalWritingMode());
}

public function testJsonSerialize(): void
Expand All @@ -51,15 +61,33 @@ public function testJsonSerialize(): void
'uri',
'pt-BR',
'Portuguese',
tao_models_classes_LanguageService::INSTANCE_ORIENTATION_LTR
tao_models_classes_LanguageService::INSTANCE_ORIENTATION_LTR,
null
);
$this->assertSame(
[
'uri' => $language->getUri(),
'code' => $language->getCode(),
'label' => $language->getLabel(),
'orientation' => $language->getOrientation(),
],
$language->jsonSerialize()
);

$language = new Language(
'uri',
'ja-JP',
'Japanese',
'ltr',
'vertical-rl'
);
$this->assertSame(
[
'uri' => $language->getUri(),
'code' => $language->getCode(),
'label' => $language->getLabel(),
'orientation' => $language->getOrientation(),
'verticalWritingMode' => $language->getVerticalWritingMode()
],
$language->jsonSerialize()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,28 @@ public function setUp(): void
public function testFindAvailableLanguagesByUsage(): void
{
$usageResource = $this->createMock(core_kernel_classes_Resource::class);
$languageResource = $this->createMock(core_kernel_classes_Resource::class);
$languageResource1 = $this->createMock(core_kernel_classes_Resource::class);
$languageResource2 = $this->createMock(core_kernel_classes_Resource::class);

$languageCode = $this->createMock(core_kernel_classes_Resource::class);
$languageCode1 = $this->createMock(core_kernel_classes_Resource::class);
$languageCode2 = $this->createMock(core_kernel_classes_Resource::class);
$orientation = $this->createMock(core_kernel_classes_Resource::class);
$verticalWritingMode2 = $this->createMock(core_kernel_classes_Resource::class);

$orientation
->method('getUri')
->willReturn(tao_models_classes_LanguageService::INSTANCE_ORIENTATION_LTR);

$languageCode
$verticalWritingMode2
->method('getUri')
->willReturn(tao_models_classes_LanguageService::INSTANCE_VERTICAL_WRITING_MODE_RL);

$languageCode1
->method('__toString')
->willReturn('code1');
$languageCode2
->method('__toString')
->willReturn('code');
->willReturn('code2');

$this->ontology
->method('getResource')
Expand All @@ -75,41 +85,72 @@ public function testFindAvailableLanguagesByUsage(): void
->method('getAvailableLanguagesByUsage')
->willReturn(
[
$languageResource
$languageResource1,
$languageResource2
]
);

$languageResource1
->method('getPropertiesValues')
->willReturn(
[
OntologyRdf::RDF_VALUE => [
0 => $languageCode1
],
tao_models_classes_LanguageService::PROPERTY_LANGUAGE_ORIENTATION => [
0 => $orientation
],
tao_models_classes_LanguageService::PROPERTY_LANGUAGE_VERTICAL_WRITING_MODE => null,
]
);

$languageResource
$languageResource2
->method('getPropertiesValues')
->willReturn(
[
OntologyRdf::RDF_VALUE => [
0 => $languageCode
0 => $languageCode2
],
tao_models_classes_LanguageService::PROPERTY_LANGUAGE_ORIENTATION => [
0 => $orientation
],
tao_models_classes_LanguageService::PROPERTY_LANGUAGE_VERTICAL_WRITING_MODE => [
0 => $verticalWritingMode2
],
]
);

$languageResource
$languageResource1
->method('getUri')
->willReturn('uri1');
$languageResource2
->method('getUri')
->willReturn('uri');
->willReturn('uri2');

$languageResource
$languageResource1
->method('getLabel')
->willReturn('label');
->willReturn('label1');
$languageResource2
->method('getLabel')
->willReturn('label2');

$collection = $this->sut->findAvailableLanguagesByUsage();

$this->assertCount(1, $collection);
$this->assertCount(2, $collection);
$this->assertSame(
[
[
'uri' => 'uri',
'code' => 'code',
'label' => 'label',
'uri' => 'uri1',
'code' => 'code1',
'label' => 'label1',
'orientation' => 'ltr'
],
[
'uri' => 'uri2',
'code' => 'code2',
'label' => 'label2',
'orientation' => 'ltr',
'verticalWritingMode' => 'vertical-rl'
]
],
json_decode(json_encode($collection->jsonSerialize()), true)
Expand Down
Loading