Skip to content

Add a ReadFile method, to read a file inside a resource pack #315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

smell-of-curry
Copy link
Contributor

I use this a lot to read .lang files to provide translations inside the proxy. For example:

// GetLangTranslationMap returns a map of translations for a specific language from a resource pack.
func GetLangTranslationMap(pack *resource.Pack, language string) (map[string]string, error) {
	languageBytes, err := pack.ReadFile("texts/" + language + ".lang")
	if err != nil {
		return nil, fmt.Errorf("error while reading language file: %w", err)
	}

	langMap := make(map[string]string)
	scanner := bufio.NewScanner(strings.NewReader(string(languageBytes)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant