Skip to content

Commit

Permalink
[Emoji] Add the gitlab locale
Browse files Browse the repository at this point in the history
  • Loading branch information
alamirault committed Apr 2, 2024
1 parent 8af61f8 commit d86cece
Show file tree
Hide file tree
Showing 7 changed files with 2,221 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ CHANGELOG
---

* Add the component
* Add the `gitlab` locale to `EmojiTransliterator`
2 changes: 2 additions & 0 deletions EmojiTransliterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ final class EmojiTransliterator extends \Transliterator
private const QUICK_CHECK = "\xA9\xAE\xE2\xE3\xF0";
private const REVERSEABLE_IDS = [
'emoji-github' => 'github-emoji',
'emoji-gitlab' => 'gitlab-emoji',
'emoji-slack' => 'slack-emoji',
'github-emoji' => 'emoji-github',
'gitlab-emoji' => 'emoji-gitlab',
'slack-emoji' => 'emoji-slack',
];

Expand Down
1 change: 1 addition & 0 deletions Resources/bin/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
update: ## Update sources
@composer update
@curl https://api.github.com/emojis > vendor/github-emojis.json
@curl https://gitlab.com/gitlab-org/gitlab/-/raw/master/fixtures/emojis/index.json > vendor/gitlab-emojis.json
@curl https://raw.githubusercontent.com/iamcal/emoji-data/master/emoji.json > vendor/slack-emojis.json
@curl -L https://unicode.org/Public/emoji/latest/emoji-test.txt > vendor/emoji-test.txt

Expand Down
30 changes: 30 additions & 0 deletions Resources/bin/build.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
Builder::saveRules(Builder::buildRules($emojisCodePoints));
Builder::saveRules(Builder::buildStripRules($emojisCodePoints));
Builder::saveRules(Builder::buildGitHubRules($emojisCodePoints));
Builder::saveRules(Builder::buildGitlabRules($emojisCodePoints));
Builder::saveRules(Builder::buildSlackRules($emojisCodePoints));

final class Builder
Expand Down Expand Up @@ -156,6 +157,35 @@ public static function buildGitHubRules(array $emojisCodePoints): iterable
return ['emoji-github' => $maps, 'github-emoji' => array_flip($maps)];
}

public static function buildGitlabRules(array $emojisCodePoints): iterable
{
$emojis = json_decode((new Filesystem())->readFile(__DIR__.'/vendor/gitlab-emojis.json'), true, flags: JSON_THROW_ON_ERROR);

$ignored = [];
$maps = [];

foreach ($emojis as $emojiItem) {
$emojiCodePoints = strtolower($emojiItem['unicode']);
if (!array_key_exists($emojiCodePoints, $emojisCodePoints)) {
$ignored[] = [
'emojiCodePoints' => $emojiCodePoints,
'name' => $emojiItem['name'],
];
continue;
}
$emoji = $emojisCodePoints[$emojiCodePoints];
if (!self::testEmoji($emoji, 'gitlab', $emojiCodePoints)) {
continue;
}
$codePointsCount = mb_strlen($emoji);
$maps[$codePointsCount][$emoji] = $emojiItem['shortname'];
}

$maps = self::createRules($maps);

return ['emoji-gitlab' => $maps, 'gitlab-emoji' => array_flip($maps)];
}

public static function buildSlackRules(array $emojisCodePoints): iterable
{
$emojis = json_decode((new Filesystem())->readFile(__DIR__.'/vendor/slack-emojis.json'), true, flags: JSON_THROW_ON_ERROR);
Expand Down
Loading

0 comments on commit d86cece

Please sign in to comment.