-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
17b0498
commit d86e3cd
Showing
4 changed files
with
166 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# command descriptions: command-description_{command} | ||
# |--------------------------------------------------------------------------------------------------| | ||
|
||
# parameter descriptions: parameter-description_{command}_{parameter} | ||
# |--------------------------------------------------------------------------------------------------| | ||
|
||
# common parameters | ||
|
||
parameter-description_common_visibility = | ||
Whether the message should be visible to everyone, or just you. | ||
# /gh issue | ||
|
||
command-description_gh-issue = | ||
Get a link to a GitHub issue. | ||
parameter-description_gh-issue_reference = | ||
Issue to look up (`owner/repo#123` or `#123`). Use `/gh login` to get autocomplete. | ||
# /gh pr | ||
|
||
command-description_gh-pr = | ||
Get a link to a GitHub pull request. | ||
parameter-description_gh-pr_reference = | ||
Pull request to look up (`owner/repo#123` or `#123`). Use `/gh login` to get autocomplete. | ||
# /gh commit | ||
|
||
command-description_gh-commit = | ||
Get a link to a GitHub commit. | ||
parameter-description_gh-commit_reference = | ||
Commit SHA to look up (`owner/repo@sha` or `@sha`). Use `/gh login` to get autocomplete. | ||
# /gh repo | ||
|
||
command-description_gh-repo = | ||
Get a link to a GitHub repository. | ||
# /gh login | ||
|
||
command-description_gh-login = | ||
Authorize GitHub Utils to make requests on behalf of your GitHub account. | ||
# /gh logout | ||
|
||
command-description_gh-logout = | ||
Remove your GitHub account from GitHub Utils. | ||
# /gh status | ||
|
||
command-description_gh-status = | ||
Show information about GitHub Utils. | ||
# /gh search | ||
|
||
command-description_gh-search = | ||
Search for things on GitHub. | ||
# /gh search files | ||
|
||
command-description_gh-search-files = | ||
Search for files in a repository by name. | ||
parameter-description_gh-search-files_repo = | ||
Repository to search in (`owner/repo`). | ||
parameter-description_gh-search-files_query = | ||
Filename to search for. | ||
parameter-description_gh-search-files_ref = | ||
Branch name, tag name, or commit to search in. Defaults to the default branch of the repo. | ||
parameter-description_gh-search-files_exact = | ||
If true, use exact search; otherwise use fuzzy search. | ||
parameter-description_gh-search-files_limit = | ||
Maximum number of results to show. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
"""Localization helpers.""" | ||
|
||
import re | ||
from typing import Mapping | ||
|
||
from discord import app_commands | ||
from discord.app_commands import locale_str | ||
|
||
type StrIterable = list[str] | tuple[str, ...] | ||
|
||
_SEPARATOR_PATTERN = re.compile(r"[ _-]+") | ||
|
||
|
||
def command_description(command: str): | ||
command = _format_command(command) | ||
return locale_str(f"command-description_{command}") | ||
|
||
|
||
def parameter_description(command: str | None, parameter: str): | ||
command = _format_command(command or "common") | ||
return locale_str(f"parameter-description_{command}_{parameter}") | ||
|
||
|
||
def describe_common(*parameters: str): | ||
return describe(common=parameters) | ||
|
||
|
||
def describe( | ||
dict_args: Mapping[str, StrIterable] | None = None, | ||
**kwargs: StrIterable, | ||
): | ||
"""Localize app command parameters. | ||
Key: command to localize parameters for. | ||
Value: parameter names. | ||
""" | ||
if dict_args: | ||
kwargs |= dict_args | ||
return app_commands.describe(**{ | ||
parameter: parameter_description(command, parameter) | ||
for command, parameters in kwargs.items() | ||
for parameter in parameters | ||
}) | ||
|
||
|
||
def _format_command(command: str): | ||
return _SEPARATOR_PATTERN.sub("-", command).replace("/", "") |