Skip to content
Snippets Groups Projects
Verified Commit 28466a32 authored by Martin Sjölund's avatar Martin Sjölund
Browse files

Added part of the translation lab

parent 241e53b9
No related branches found
No related tags found
No related merge requests found
*-main.c
*.mo
gettext
all: gettext-main.c linguist-main.c
gettext: gettext-main.c setuplocale.c gettext.c
gettext-main.c: base.c
cp $< $@
linguist-main.c: base.c
cp $< $@
#include <stdio.h>
void setup();
void setuplocale();
int main(int argc, char** argv)
{
setuplocale();
setup();
/* TODO: You need to update this code to output translated strings
* Note that you should make gettext-main.c linguist-main.c and modify
* those files rather than base.c
*/
printf("The current language is the default (C/POSIX)\n");
printf("The horse can run.\n");
printf("How fast can the horse run?\n");
printf("It typically runs at speed of less than 50 km/h.\n");
return 0;
}
#include <locale.h>
#include <libintl.h>
#include <stdio.h>
#include <stdlib.h>
void setup()
{
/* Your code here. Setup a domain for gettext. */
}
#include <stdlib.h>
#include <stdio.h>
#include <locale.h>
void setuplocale()
{
/* Usually, the locale is taken from the user's environment.
* We have hard-coded a locale for purposes of this lab.
*/
char *newlocale, *targetLocale = "sv_SE.utf8";
setenv("LANGUAGE", targetLocale, 1);
setenv("LANG", targetLocale, 1);
setenv("LC_MESSAGES", targetLocale, 1);
newlocale = setlocale(LC_MESSAGES, targetLocale);
if (newlocale == NULL) {
fprintf(stderr, "Error: %s locale not installed (perhaps use a different hard-coded locale as a work-around)\n", targetLocale);
exit(1);
}
printf("Set locale to: %s\n", newlocale);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment