Skip to content

Commit

Permalink
update some for docu
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed May 27, 2020
1 parent f638ffd commit df30225
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .ptool.example.inc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ return [
],
// tool command usage docs
'manDocs' => [
'lang' => 'en',
// if 'lang' not setting, will read from ENV.
// 'lang' => 'en',
'paths' => [
'root' => BASE_PATH . '/docs'
],
Expand Down
3 changes: 2 additions & 1 deletion app/Console/Command/DocCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Inhere\Console\IO\Input;
use Inhere\Console\IO\Output;
use Inhere\PTool\Common\CliMarkdown;
use Inhere\PTool\Helper\AppHelper;
use Inhere\PTool\ManDoc\Document;
use Toolkit\Cli\Color;
use function rtrim;
Expand Down Expand Up @@ -83,7 +84,7 @@ private function prepareManDoc(): Document
$paths = $info['paths'] ?? [];
$lang = $this->input->getStringOpt('lang');
if (!$lang) {
$lang = $info['lang'] ?? Document::DEF_LANG;
$lang = $info['lang'] ?? AppHelper::getLangFromENV(Document::DEF_LANG);
}

$man = new Document($paths, $lang);
Expand Down
28 changes: 28 additions & 0 deletions app/Helper/AppHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use Inhere\Console\Util\Show;
use Toolkit\Sys\Sys;
use function explode;
use function getenv;
use function strpos;
use function trim;

/**
Expand All @@ -13,6 +16,10 @@
*/
class AppHelper
{
public const LANG_MAP = [
'zh_CN' => 'zh-CN',
];

/**
* @param string $tag
*
Expand All @@ -28,6 +35,27 @@ public static function formatTag(string $tag): string
return 'v' . $tag;
}

/**
* env: LC_CTYPE=zh_CN.UTF-8
*
* @param string $default
*
* @return string
*/
public static function getLangFromENV(string $default = ''): string
{
$value = getenv('LC_CTYPE');

// zh_CN.UTF-8
if (strpos($value, '.') > 0) {
[$value, ] = explode('.', $value);

return self::LANG_MAP[$value] ?? $value;
}

return $default;
}

/**
* Open browser URL
*
Expand Down
2 changes: 1 addition & 1 deletion app/ManDoc/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Document
* @param array $paths
* @param string $lang
*/
public function __construct(array $paths, string $lang = 'en')
public function __construct(array $paths, string $lang)
{
$this->paths = $paths;
$this->lang = $lang;
Expand Down

0 comments on commit df30225

Please sign in to comment.