文件最后提交记录最后更新时间
An translation example that uses the embed package. A very simple example that shows how a message on a webpage can be translated into multiple languages. The user sets their language preference via a set of radio buttons on the web page. The message is then translated to the seclected language. The translation is based on a set of language files, one per supported language. These files are embedded within the WASM binary using the standard go embed package. The translation is provided via the go-i18n package, which loads the language files from the WASM binary prior to translation. 1 年前
An translation example that uses the embed package. A very simple example that shows how a message on a webpage can be translated into multiple languages. The user sets their language preference via a set of radio buttons on the web page. The message is then translated to the seclected language. The translation is based on a set of language files, one per supported language. These files are embedded within the WASM binary using the standard go embed package. The translation is provided via the go-i18n package, which loads the language files from the WASM binary prior to translation. 1 年前
An translation example that uses the embed package. A very simple example that shows how a message on a webpage can be translated into multiple languages. The user sets their language preference via a set of radio buttons on the web page. The message is then translated to the seclected language. The translation is based on a set of language files, one per supported language. These files are embedded within the WASM binary using the standard go embed package. The translation is provided via the go-i18n package, which loads the language files from the WASM binary prior to translation. 1 年前
An translation example that uses the embed package. A very simple example that shows how a message on a webpage can be translated into multiple languages. The user sets their language preference via a set of radio buttons on the web page. The message is then translated to the seclected language. The translation is based on a set of language files, one per supported language. These files are embedded within the WASM binary using the standard go embed package. The translation is provided via the go-i18n package, which loads the language files from the WASM binary prior to translation. 1 年前
An translation example that uses the embed package. A very simple example that shows how a message on a webpage can be translated into multiple languages. The user sets their language preference via a set of radio buttons on the web page. The message is then translated to the seclected language. The translation is based on a set of language files, one per supported language. These files are embedded within the WASM binary using the standard go embed package. The translation is provided via the go-i18n package, which loads the language files from the WASM binary prior to translation. 1 年前
Upgrade all dependencies 1 年前
Update the generated code for examples after the noshadow changes Update the generated code used inthe examples, following theremoval of the noshadow option. The impacted examples are: dom-events embed-and-translate fetch-and-display html-form vg-for vg-if 1 年前
Upgrade all dependencies Upgraded all dependencies, including tests, examples and wasm-test-suite. The list of upgrades is: go: upgraded go 1.22.3 => 1.23 go: added toolchain go1.23.5 go: upgraded github.com/chromedp/cdproto v0.0.0-20240810084448-b931b754e476 => v0.0.0-20250120090109-d38428e4d9c8 go: upgraded github.com/chromedp/chromedp v0.10.0 => v0.11.2 go: upgraded github.com/chromedp/sysutil v1.0.0 => v1.1.0 go: upgraded github.com/mailru/easyjson v0.7.7 => v0.9.0 go: upgraded github.com/stretchr/testify v1.9.0 => v1.10.0 go: upgraded golang.org/x/sys v0.24.0 => v0.29.0 go: upgraded github.com/nicksnyder/go-i18n/v2 v2.4.0 => v2.4.1 go: upgraded golang.org/x/text v0.14.0 => v0.21.0 go: upgraded golang.org/x/text v0.14.0 => v0.21.0 go: upgraded github.com/stretchr/testify v1.9.0 => v1.10.0 1 年前
An translation example that uses the embed package. A very simple example that shows how a message on a webpage can be translated into multiple languages. The user sets their language preference via a set of radio buttons on the web page. The message is then translated to the seclected language. The translation is based on a set of language files, one per supported language. These files are embedded within the WASM binary using the standard go embed package. The translation is provided via the go-i18n package, which loads the language files from the WASM binary prior to translation. 1 年前
An translation example that uses the embed package. A very simple example that shows how a message on a webpage can be translated into multiple languages. The user sets their language preference via a set of radio buttons on the web page. The message is then translated to the seclected language. The translation is based on a set of language files, one per supported language. These files are embedded within the WASM binary using the standard go embed package. The translation is provided via the go-i18n package, which loads the language files from the WASM binary prior to translation. 1 年前
An translation example that uses the embed package. A very simple example that shows how a message on a webpage can be translated into multiple languages. The user sets their language preference via a set of radio buttons on the web page. The message is then translated to the seclected language. The translation is based on a set of language files, one per supported language. These files are embedded within the WASM binary using the standard go embed package. The translation is provided via the go-i18n package, which loads the language files from the WASM binary prior to translation. 1 年前
An translation example that uses the embed package. A very simple example that shows how a message on a webpage can be translated into multiple languages. The user sets their language preference via a set of radio buttons on the web page. The message is then translated to the seclected language. The translation is based on a set of language files, one per supported language. These files are embedded within the WASM binary using the standard go embed package. The translation is provided via the go-i18n package, which loads the language files from the WASM binary prior to translation. 1 年前
An translation example that uses the embed package. A very simple example that shows how a message on a webpage can be translated into multiple languages. The user sets their language preference via a set of radio buttons on the web page. The message is then translated to the seclected language. The translation is based on a set of language files, one per supported language. These files are embedded within the WASM binary using the standard go embed package. The translation is provided via the go-i18n package, which loads the language files from the WASM binary prior to translation. 1 年前
An translation example that uses the embed package. A very simple example that shows how a message on a webpage can be translated into multiple languages. The user sets their language preference via a set of radio buttons on the web page. The message is then translated to the seclected language. The translation is based on a set of language files, one per supported language. These files are embedded within the WASM binary using the standard go embed package. The translation is provided via the go-i18n package, which loads the language files from the WASM binary prior to translation. 1 年前
Readme.md

embed-and-translate example

A very simple example that primarily demonstrates:

  1. The use of the embed package to embed static files in the WASM binary. In this case the embedded files are language translation files.
  2. Using an go-i18n package to translate messages into the correct language based on user input from a set of radio buttons.

This example is not intended to be a complete example of the embed or go-i18n packages. It only shows how both could be used in a vugu application.

The language files where generated by hand. In particular they did not make use of the goi18n tool that assists in the creation of language translation files, as a result no additional tooling is required to build and run this example.

In a production setting, you may need to run the goi18n tool to create an manage any language files. This additional step would need to be added to your build process.

Building the example

This build instructions are based on using mage as the built tool. If you require a different built tool please use the generic method of building in the Readme at the root of the examples package.

Building the example is easy.

You will need docker and mage preinstalled before you begin.

First you must clone the vugu repository:

git clone https://github.com/vugu/vugu

Now cd into the cloned repository directory

cd vugu

The vugu project uses mage as its preferred build tool, so building the example is simply

mage SingleExample github.com/vugu/vugu/examples/embed-and-translate

If that works then in the shell you will see:

Local nginx container started.
Connect to http://localhost:8889/<example-test-directory-name>
e,g. http://localhost:8889/fetch-and-display
To stop the local nginx container please run:
	mage StopLocalNginxForExamples

The mage SingleExample github.com/vugu/vugu/examples/embed-and-translate command will build the example in question, as well as all of the vugu tools. This ensures that the example is always built with the latest version of the vugu tools.

Running the example

To run the example, we follow the instructions in the shell.

Open a browser at http://localhost:8889/embed-and-translate/

And the example will load and run.

Changing the example

Changing the example is also easy.

The general principle is that you should update the root.go or root.vugu files as needed and then rerun mage SingleExample github.com/vugu/vugu/examples/embed-and-translate, then refresh the browser so that it loads new wasm example binary.

So for example update the Root.ListLength() method from:

// Return the current list length
func (c *Root) ListLength() int {
	return len(c.list)
}

to

// Return the current list length
func (c *Root) ListLength() int {
    fmt.Printf("Current list length: %d\n", len(c.list))
	return len(c.list)
}

Then run

mage SingleExample github.com/vugu/vugu/examples/embed-and-translate

Again browse to http://localhost:8889/embed-and-translate/ and refresh the browser.

You should now see the list length being displayed in the JavaScript console when the list is rendered.