mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 17:59:48 +00:00
Added base translation system
This commit is contained in:
159
src/pocketmine/lang/BaseLang.php
Normal file
159
src/pocketmine/lang/BaseLang.php
Normal file
@ -0,0 +1,159 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
namespace pocketmine\lang;
|
||||
|
||||
use pocketmine\event\TextContainer;
|
||||
use pocketmine\event\TranslationContainer;
|
||||
|
||||
class BaseLang{
|
||||
|
||||
const FALLBACK_LANGUAGE = "en";
|
||||
|
||||
protected $langName;
|
||||
|
||||
protected $lang = [];
|
||||
protected $fallbackLang = [];
|
||||
|
||||
public function __construct($lang, $path = null){
|
||||
|
||||
$this->langName = strtolower($lang);
|
||||
|
||||
if($path === null){
|
||||
$path = \pocketmine\PATH . "src/pocketmine/lang/base/";
|
||||
}
|
||||
|
||||
$this->loadLang($path . $this->langName . ".ini", $this->lang);
|
||||
$this->loadLang($path . self::FALLBACK_LANGUAGE . ".ini", $this->fallbackLang);
|
||||
}
|
||||
|
||||
public function getName(){
|
||||
return $this->get("language.name");
|
||||
}
|
||||
|
||||
public function getLang(){
|
||||
return $this->langName;
|
||||
}
|
||||
|
||||
protected function loadLang($path, array &$d){
|
||||
if(file_exists($path) and strlen($content = file_get_contents($path)) > 0){
|
||||
foreach(explode("\n", $content) as $line){
|
||||
$line = trim($line);
|
||||
if($line === "" or $line{0} === "#"){
|
||||
continue;
|
||||
}
|
||||
|
||||
$t = explode("=", $line);
|
||||
if(count($t) < 2){
|
||||
continue;
|
||||
}
|
||||
|
||||
$key = trim(array_shift($t));
|
||||
$value = trim(implode("=", $t));
|
||||
|
||||
if($value === ""){
|
||||
continue;
|
||||
}
|
||||
|
||||
$d[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function translate(TextContainer $c){
|
||||
if($c instanceof TranslationContainer){
|
||||
$baseText = $this->get($c->getText());
|
||||
$baseText = $this->parseTranslation( $baseText !== null ? $baseText : $c->getText());
|
||||
|
||||
foreach($c->getParameters() as $i => $p){
|
||||
$baseText = str_replace("{%$i}", $this->parseTranslation($p), $baseText);
|
||||
}
|
||||
}else{
|
||||
$baseText = $this->parseTranslation($c->getText());
|
||||
}
|
||||
|
||||
return $baseText;
|
||||
}
|
||||
|
||||
public function internalGet($id){
|
||||
if(isset($this->lang[$id])){
|
||||
return $this->lang[$id];
|
||||
}elseif(isset($this->fallbackLang[$id])){
|
||||
return $this->fallbackLang[$id];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function get($id){
|
||||
$id = trim($id, "%");
|
||||
if(isset($this->lang[$id])){
|
||||
return $this->lang[$id];
|
||||
}elseif(isset($this->fallbackLang[$id])){
|
||||
return $this->fallbackLang[$id];
|
||||
}
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
protected function parseTranslation($text){
|
||||
$newString = "";
|
||||
|
||||
$replaceString = null;
|
||||
|
||||
$len = strlen($text);
|
||||
for($i = 0; $i < $len; ++$i){
|
||||
$c = $text{$i};
|
||||
if($replaceString !== null){
|
||||
if((ord($c) >= 0x30 and ord($c) <= 0x39) or (ord($c) >= 0x41 and ord($c) <= 0x5a) or (ord($c) >= 0x61 and ord($c) <= 0x7a) or $c === "."){
|
||||
$replaceString .= $c;
|
||||
}else{
|
||||
if(($t = $this->internalGet(substr($replaceString, 1)))){
|
||||
$newString .= $t;
|
||||
}else{
|
||||
$newString .= $replaceString;
|
||||
}
|
||||
$replaceString = null;
|
||||
|
||||
if($c === "%"){
|
||||
$replaceString = $c;
|
||||
}else{
|
||||
$newString .= $c;
|
||||
}
|
||||
}
|
||||
}elseif($c === "%"){
|
||||
$replaceString = $c;
|
||||
}else{
|
||||
$newString .= $c;
|
||||
}
|
||||
}
|
||||
|
||||
if($replaceString !== null){
|
||||
if(($t = $this->internalGet(substr($replaceString, 1)))){
|
||||
$newString .= $t;
|
||||
}else{
|
||||
$newString .= $replaceString;
|
||||
}
|
||||
}
|
||||
|
||||
return $newString;
|
||||
}
|
||||
}
|
84
src/pocketmine/lang/base/en.ini
Normal file
84
src/pocketmine/lang/base/en.ini
Normal file
@ -0,0 +1,84 @@
|
||||
# Language file compatible with Minecraft: Pocket Edition identifiers
|
||||
#
|
||||
# A message doesn't need to be there to be shown correctly on the client.
|
||||
# Only messages shown in PocketMine itself need to be here
|
||||
|
||||
language.name=English
|
||||
|
||||
multiplayer.player.joined={%0} joined the game
|
||||
multiplayer.player.leave={%0} left the game
|
||||
|
||||
death.fell.accident.generic={%0} fell from a high place
|
||||
death.attack.inFire={%0} went up in flames
|
||||
death.attack.onFire={%0} burned to death
|
||||
death.attack.lava={%0} tried to swim in lava
|
||||
death.attack.inWall={%0} suffocated in a wall
|
||||
death.attack.drown={%0} drowned
|
||||
death.attack.cactus={%0} was pricked to death
|
||||
death.attack.generic={%0} died
|
||||
death.attack.explosion={%0} blew up
|
||||
death.attack.explosion.player={%0} was blown up by {%1}
|
||||
death.attack.magic={%0} was killed by magic
|
||||
death.attack.wither={%0} withered away
|
||||
death.attack.mob={%0} was slain by {%1}
|
||||
death.attack.player={%0} was slain by {%1}
|
||||
death.attack.player.item={%0} was slain by {%1} using {%2}
|
||||
death.attack.arrow={%0} was shot by {%1}
|
||||
death.attack.arrow.item={%0} was shot by {%1} using {%2}
|
||||
death.attack.fall={%0} hit the ground too hard
|
||||
death.attack.outOfWorld={%0} fell out of the world
|
||||
|
||||
gameMode.survival=Survival Mode
|
||||
gameMode.creative=Creative Mode
|
||||
gameMode.adventure=Adventure Mode
|
||||
gameMode.spectator=Spectator Mode
|
||||
gameMode.changed=Your game mode has been updated
|
||||
|
||||
potion.moveSpeed=Speed
|
||||
potion.moveSlowdown=Slowness
|
||||
potion.digSpeed=Haste
|
||||
potion.digSlowDown=Mining Fatigue
|
||||
potion.damageBoost=Strength
|
||||
potion.heal=Instant Health
|
||||
potion.harm=Instant Damage
|
||||
potion.jump=Jump Boost
|
||||
potion.confusion=Nausea
|
||||
potion.regeneration=Regeneration
|
||||
potion.resistance=Resistance
|
||||
potion.fireResistance=Fire Resistance
|
||||
potion.waterBreathing=Water Breathing
|
||||
potion.invisibility=Invisibility
|
||||
potion.blindness=Blindness
|
||||
potion.nightVision=Night Vision
|
||||
potion.hunger=Hunger
|
||||
potion.weakness=Weakness
|
||||
potion.poison=Poison
|
||||
potion.wither=Wither
|
||||
potion.healthBoost=Health Boost
|
||||
potion.absorption=Absorption
|
||||
potion.saturation=Saturation
|
||||
|
||||
commands.generic.exception=An unknown error occurred while attempting to perform this command
|
||||
commands.generic.permission=You do not have permission to use this command
|
||||
commands.generic.notFound=Unknown command. Try /help for a list of commands
|
||||
commands.generic.usage=Usage: {%0}
|
||||
|
||||
commands.give.item.notFound=There is no such item with name {%0}
|
||||
commands.give.success=Given {%0} * {%1} to {%2}
|
||||
|
||||
commands.effect.usage=/effect <player> <effect> [seconds] [amplifier] [hideParticles] OR /effect <player> clear
|
||||
commands.effect.notFound=There is no such mob effect with ID {%0}
|
||||
commands.effect.success=Given {%0} (ID {%1}) * {%2} to {%3} for {%4} seconds
|
||||
commands.effect.success.removed=Took {%0} from {%1}
|
||||
commands.effect.success.removed.all=Took all effects from {%0}
|
||||
commands.effect.failure.notActive=Couldn't take {%0} from {%1} as they do not have the effect
|
||||
commands.effect.failure.notActive.all=Couldn't take any effects from {%0} as they do not have any
|
||||
|
||||
commands.particle.success=Playing effect {%0} for {%1} times
|
||||
commands.particle.notFound=Unknown effect name {%0}
|
||||
|
||||
commands.players.usage=/list
|
||||
commands.players.list=There are {%0}/{%1} players online:
|
||||
|
||||
commands.defaultgamemode.usage=/defaultgamemode <mode>
|
||||
commands.defaultgamemode.success=The world's default game mode is now {%0}
|
Reference in New Issue
Block a user