aboutsummaryrefslogtreecommitdiff
path: root/engine/LangData.php
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2024-01-31 06:11:00 +0300
committerEvgeny Zinoviev <me@ch1p.io>2024-01-31 20:45:40 +0300
commitc0dc531ebefd8912819f3b6c8bda1fed3c7e750c (patch)
tree2c75aa9df182260aef09faf4befd81a4c2b9c5e2 /engine/LangData.php
parent48d688cdf7f9eae1bf11b8a6f0e5b98687c604cb (diff)
make it simple, but not simpler
Diffstat (limited to 'engine/LangData.php')
-rw-r--r--engine/LangData.php108
1 files changed, 0 insertions, 108 deletions
diff --git a/engine/LangData.php b/engine/LangData.php
deleted file mode 100644
index 6f108f2..0000000
--- a/engine/LangData.php
+++ /dev/null
@@ -1,108 +0,0 @@
-<?php
-
-class LangData implements ArrayAccess {
-
- private static ?LangData $instance = null;
- protected array $data = [];
- protected array $loaded = [];
-
- public static function getInstance(): static {
- if (is_null(self::$instance)) {
- self::$instance = new self();
- self::$instance->load('en');
- }
- return self::$instance;
- }
-
- public function __invoke(string $key, ...$args) {
- $val = $this[$key];
- return empty($args) ? $val : sprintf($val, ...$args);
- }
-
- public function load(string $name) {
- if (array_key_exists($name, $this->loaded))
- return;
-
- $data = require_once ROOT."/lang/{$name}.php";
- $this->data = array_replace($this->data,
- $data);
-
- $this->loaded[$name] = true;
- }
-
- public function offsetSet(mixed $offset, mixed $value): void {
- logError(__METHOD__ . ': not implemented');
- }
-
- public function offsetExists($offset): bool {
- return isset($this->data[$offset]);
- }
-
- public function offsetUnset(mixed $offset): void {
- logError(__METHOD__ . ': not implemented');
- }
-
- public function offsetGet(mixed $offset): mixed {
- return $this->data[$offset] ?? '{' . $offset . '}';
- }
-
- public function search(string $regexp): array|false {
- return preg_grep($regexp, array_keys($this->data));
- }
-
- // function plural(array $s, int $n, array $opts = []) {
- // $opts = array_merge([
- // 'format' => true,
- // 'format_delim' => ' ',
- // 'lang' => 'en',
- // ], $opts);
- //
- // switch ($opts['lang']) {
- // case 'ru':
- // $n = $n % 100;
- // if ($n > 19)
- // $n %= 10;
- //
- // if ($n == 1) {
- // $word = 0;
- // } else if ($n >= 2 && $n <= 4) {
- // $word = 1;
- // } else if ($n == 0 && count($s) == 4) {
- // $word = 3;
- // } else {
- // $word = 2;
- // }
- // break;
- //
- // default:
- // if (!$n && count($s) == 4) {
- // $word = 3;
- // } else {
- // $word = (int)!!$n;
- // }
- // break;
- // }
- //
- // // if zero
- // if ($word == 3)
- // return $s[3];
- //
- // if (is_callable($opts['format'])) {
- // $num = $opts['format']($n);
- // } else if ($opts['format'] === true) {
- // $num = formatNumber($n, $opts['format_delim']);
- // }
- //
- // return sprintf($s[$word], $num);
- // }
- //
- // function formatNumber(int $num, string $delim = ' ', bool $short = false): string {
- // if ($short) {
- // if ($num >= 1000000)
- // return floor($num / 1000000).'m';
- // if ($num >= 1000)
- // return floor($num / 1000).'k';
- // }
- // return number_format($num, 0, '.', $delim);
- // }
-}