We introduce a method for learning to generate machine translation of a given sentence with potential rare named entities (NE). In our approach, NEs and their translations are extracted from a bilingual knowledge base, aimed at maximizing correct translations for under-represented named entities in a parallel corpus. The method involves linking NEs in the bilingual training sentences, replacing NEs with NE-type labels, and training a neural machine translation (NMT) model for partially lexicalized training data with regular tokens and NE-type labels. At run time, the system accepts a text passage, links and replaces NEs with NE-type labels, and then translates the text using the trained NMT model and translate NE-type labels using a bilingual knowledge base. We present a prototype system, WikiTrans that applies the method to a parallel corpus and extit{Wikipedia}. Evaluation on a set of sentences shows that the method achieves reasonably good performance in terms of generating high quality NE translations and enhancing the fluency of target sentences.