Weblate 前端¶
The frontend is currently built using Bootstrap, jQuery and few third-party libraries.
Supported browsers¶
Weblate 支援所有主要瀏覽器和平台的最新的、穩定的版本。
不明確支援使用最新版的 WebKit、Blink 或 Gecko的替換瀏覽器,無論是否直接還是通過平台的 web 視圖 API。然而,Weblate應該(在多數情況下)頁在這些瀏覽器中正常顯示並工作。
其它瀏覽器也能工作,但一些特性會受到限制。
相依性管理¶
Installing and managing 3rd party libraries in the client of a Django project can be a bit tricky. This section provides a step-by-step guide on how to install and manage 3rd party libraries used by the client side of Weblate using Webpack.
Prerequisites¶
Before proceeding with an installation, make sure you have the following prerequisites:
Nodejsversion 14 or higher.The
yarnpackage manager is installed on your system.Run
cd client.Run
yarn install
安裝¶
To install a library, first run the following command:
yarn add <lib-name>
Importing the Library¶
Then, there are two ways to import the library:
- If it is a project-wide library (it is used/needed in all/most pages):
Import the library in
src/main.js.And declare it in the global scope (if needed).
- If it is page-specific library (library is used in a specific page or template):
Create a new file named
src/<lib-name>.js.Import the library in it. Then inject it into the
windowobject to be globally accessible.Add an entry in
webpack.config.js:<lib-name>: "src/<lib-name>.js".Add library name in
excludePrefixesarray inmainLicenseTransforminwebpack.config.js.Add license file name in
additionalFilesinLicensePlugininpluginsarray inwebpack.config.js.Create a
<lib-name>LicenseTransfromfunction for the license file introduced in the previous steps and use it.
Note: Replace
<lib-name>with the actual name of the 3rd party library.
Building the Library¶
Build the libraries used by the project, by running the following command:
yarn build
Including the Library¶
Now the library is built and ready for use. To include it follow these steps:
If the library was imported in
src/main.js, no further steps are required (as it is already included inbase.html).If the library was imported in its specific file
src/<lib-name>.js, inweblate/templatesuse the include tags to link to the built static JavaScript file:
{% load static %}
<script src="{% static 'js/vendor/<lib-name>.js' %}"></script>
編碼風格¶
Weblate relies on Biome for formatting and linting the JavaScript and CSS code.
在地化¶
Should you need any user visible text in the frontend code, it should be
localizable. In most cases, all you need is to wrap your text inside gettext
function, but there are more complex features available:
document.write(gettext('this is to be translated'));
var object_count = 1 // or 0, or 2, or 3, ...
s = ngettext('literal for the singular case',
'literal for the plural case', object_count);
fmts = ngettext('There is %s object. Remaining: %s',
'There are %s objects. Remaining: %s', 11);
s = interpolate(fmts, [11, 20]);
// s is 'There are 11 objects. Remaining: 20'
也參考
django文件中的翻譯主題
圖示¶
Weblate 目前使用 material design 圖標。如果您想找新的符號,檢查 Material Design Icons 或 Material Design Resources。
此外,有 scripts/optimize-svg 來減小 SVG 的大小,因為多數圖標嵌入在 HTML 中,而使路徑有風格。